> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lazylocales.com/llms.txt
> Use this file to discover all available pages before exploring further.

# check

> Scan codebase for translation key usage and report unused/missing keys

The `check` command scans your codebase for translation key usage and reports unused keys in your source file and missing keys that are referenced but not defined.

## Usage

```bash theme={null}
npx lazylocales check [options]
```

## Options

| Flag     | Description                  |
| -------- | ---------------------------- |
| `--json` | Output machine-readable JSON |

## What it does

<Steps>
  <Step title="Load source file">
    Reads your source locale file and extracts all translation keys.
  </Step>

  <Step title="Scan codebase">
    Recursively scans your project for translation function calls:

    * `t('namespace.key')` — i18next/react-i18next
    * `formatMessage({ id: 'namespace.key' })` — react-intl

    Scans TypeScript, JavaScript, Vue, Svelte, and Astro files.
  </Step>

  <Step title="Report findings">
    Shows three lists:

    **Used keys** — keys found in both source file and codebase

    **Unused keys** — keys in source file but not referenced in code

    **Missing keys** — keys referenced in code but not in source file

    ```
    ✓ 138 keys in source file
    ✓ 135 keys used in codebase

    ⚠ 3 unused keys (in source but not in code):
      • settings.notifications.sms
      • auth.passwordResetExpired
      • dashboard.chartLegend

    ⚠ 0 missing keys (in code but not in source)

    Summary:
      Used:    135
      Unused:  3
      Missing: 0
    ```
  </Step>
</Steps>

## Examples

Check for unused/missing keys:

```bash theme={null}
npx lazylocales check
```

Get results as JSON:

```bash theme={null}
npx lazylocales check --json
```

## Notes

<AccordionGroup>
  <Accordion title="What files are scanned?">
    The command scans `.ts`, `.tsx`, `.js`, `.jsx`, `.vue`, `.svelte`, and `.astro` files.

    It skips directories like `node_modules`, `.git`, `.next`, `dist`, `build`, `.turbo`, `.vercel`, and `coverage`.
  </Accordion>

  <Accordion title="How are keys detected?">
    The command uses regex patterns to find translation function calls:

    * Pattern 1: `t('namespace.key')` — matches i18next
    * Pattern 2: `formatMessage({ id: 'namespace.key' })` — matches react-intl

    Only keys with at least one dot (e.g., `auth.login`) are counted to avoid false positives from other APIs like `path.split('.')` or `.get('Authorization')`.
  </Accordion>

  <Accordion title="What about dynamic keys?">
    Dynamic keys like `t(\`errors.\${errorCode}\`)\` are **not detected** by this command.

    If you use dynamic key construction, you may see "unused" warnings for keys that are actually used dynamically.
  </Accordion>

  <Accordion title="When should I run this?">
    Run `check` periodically to:

    * Find dead keys that can be removed
    * Catch missing translations before runtime errors
    * Keep your locale files clean and maintainable

    Consider adding it to your CI pipeline to catch missing keys in pull requests.
  </Accordion>
</AccordionGroup>
