---
title: "CLI and x18n check"
description: "Check locale files like tsc, read and change keys from the terminal, and pick a reporter for CI."
canonical_url: "https://x18n.dev/surfaces/cli"
---
# CLI and x18n check

> Check locale files like tsc, read and change keys from the terminal, and pick a reporter for CI.

The `x18n` CLI is for humans, CI and agents. Every command prints human output by default, and the [JSON contract](https://x18n.dev/references/json-contracts) with `--json`. The [CLI reference](https://x18n.dev/references/cli) lists every command and option.

Run `x18n` with no command to see the status of the project and the main commands.

## x18n check

`x18n check` runs every [check](https://x18n.dev/checks) on every project and reports the diagnostics. It is to i18n what `tsc --noEmit` is to types:

```sh
x18n check
```

```
src/App.vue:17:15
 ERROR  "app.titel" is not defined in en.  missing-key
16 │   <main>
17 │     <p>{{ $t('app.titel') }}</p>
   │               ~~~~~~~~~
18 │   </main>

src/locales/de.json:8:6
 WARNING  "nav.about" is empty in de.  empty-translation
7 │   "nav": {
8 │     "about": ""
  │      ~~~~~
9 │   }

✖ 1 error  ⚠ 1 warning  2 files
```

Each problem starts with the path, the line and the column. The next line has the severity, the message and the check id. A code frame follows, with one line of context on each side. The last line counts the errors, the warnings and the files. Paths are relative to the current directory, so editors and terminals can open them.

### Options

| Option               | Effect                                                                                                   |
| -------------------- | -------------------------------------------------------------------------------------------------------- |
| `--strict`           | Turn every warning into an error. The config option `strict: true` does the same.                        |
| `--max-warnings <n>` | Fail when there are more than `n` warnings.                                                              |
| `--only <checks>`    | Run only these check ids, for example `--only placeholder-mismatch,invalid-syntax`.                      |
| `--skip <checks>`    | Skip these check ids.                                                                                    |
| `--locale <locale>`  | Report only for these locales. Diagnostics without a locale stay.                                        |
| `--watch`            | Check again when a file changes.                                                                         |
| `--reporter <id>`    | Pick the output format. See [Reporters](https://x18n.dev/surfaces/cli#reporters).                        |
| `--output <file>`    | Write the output of a reporter to a file.                                                                |
| `--update-baseline`  | Write the current diagnostics into the baseline. See [Baseline](https://x18n.dev/surfaces/cli#baseline). |
| `--baseline <file>`  | Use another baseline file than `.x18n/check-baseline.json`.                                              |
| `--fix`              | Apply the safe fixes, then report what is left. See [Fixes](https://x18n.dev/surfaces/cli#fixes).        |
| `--fix=unsafe`       | Also apply the fixes that delete.                                                                        |
| `--dry-run`          | With `--fix`: show the changes, write nothing.                                                           |

To change the severity of a check for every run, use `checks` in the config. See [Checks](https://x18n.dev/checks).

### Exit codes

| Exit code | Meaning                                                     |
| --------- | ----------------------------------------------------------- |
| `0`       | No errors, and no more warnings than `--max-warnings`.      |
| `1`       | At least one error, or more warnings than `--max-warnings`. |
| `2`       | The config or the command line is invalid.                  |

[Exit codes](https://x18n.dev/references/cli#exit-codes) lists the codes of every command.

### Baseline

On a project with many known problems, a baseline makes CI fail only on new ones. Write it once and commit it:

```sh
x18n check --update-baseline
```

This writes every diagnostic into `.x18n/check-baseline.json`, in the root of the workspace. While the file exists, `x18n check` reports and fails only on diagnostics that are not in it, and says how many known ones it left out. A diagnostic is known by its file, check, key, locale and message, not by its line, so moving code keeps it known. One more identical diagnostic in the same file is new.

When you fix known problems, `x18n check` says how many entries no longer occur. Run `x18n check --update-baseline` again to drop them, so that they cannot come back unnoticed. With `--only`, `--skip` or `--locale`, the update keeps the entries that these options leave out. `--json` adds the counts as `data.baseline`: `{ "suppressed": 6, "fixed": 0 }`.

The editor and the UI still show every diagnostic. The idea comes from [i18next-cli](https://github.com/i18next/i18next-cli) and the bulk suppressions of ESLint.

### Fixes

`x18n check --fix` applies the fixes of the reported diagnostics in one write per file, then reports what is left. Fixes that only add are safe, so `--fix` applies them. Fixes that delete can lose translations, so they need `--fix=unsafe`. With `--only`, the fixes of other checks stay out:

```sh
x18n check --fix --only missing-key                     # add the keys the code uses
x18n check --fix=unsafe --only missing-key,unused-key   # also delete the keys it does not use
x18n check --fix=unsafe --dry-run                       # show the changes, write nothing
```

| Check                   | Fix                                                                                                                                                                    | With           |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| `missing-key`           | Adds the key to the source locale, with the default value from the code or an empty value. A key that would replace a message or other keys is skipped with a warning. | `--fix`        |
| `unused-key`            | Deletes the key in every locale. A key that a dynamic usage in a scope may reach stays, as with `x18n delete --unused`.                                                | `--fix=unsafe` |
| `redundant-translation` | Deletes the message that equals its fallback.                                                                                                                          | `--fix=unsafe` |

Other fixes, such as copying the source value or resolving a review, are quick fixes in the editor only. The summary goes to stderr, so the report on stdout stays clean. `--json` adds `fix` to each project: `{ "applied": true, "fixed": 3, "skipped": 1, "files": [...], "warnings": [] }`. `skipped` counts the problems that only have an unsafe fix. `--fix` does not run with `--watch`.

### Reporters

A reporter turns diagnostics into text. Pick one or more with `--reporter`:

| Reporter   | Output                                                                                                              |
| ---------- | ------------------------------------------------------------------------------------------------------------------- |
| `pretty`   | The default. The path and position, the severity badge with the message and check id, a code frame, then a summary. |
| `json`     | The JSON contract. `--json` picks it too.                                                                           |
| `markdown` | A summary, a coverage table per locale and a table of diagnostics. For pull request comments and job summaries.     |
| `github`   | GitHub Actions workflow commands. GitHub shows them as annotations on the changed lines.                            |
| `sarif`    | SARIF 2.1.0, for code scanning.                                                                                     |

`--reporter` and `--output` are repeatable. The first `--output` belongs to the first `--reporter`, the second to the second, and so on. A reporter without an `--output` prints to stdout:

```sh
x18n check --reporter markdown --output summary.md --reporter pretty
```

This command writes the markdown report to `summary.md` and prints the pretty output. See [CI](https://x18n.dev/surfaces/ci) for workflow examples.

## Read keys and usages

| Command               | Shows                                                                                                              |
| --------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `x18n status`         | Locales with coverage, and the counts of resources, keys, usages and diagnostics.                                  |
| `x18n keys [glob]`    | Keys. `--missing <locale>`, `--unused` and `--namespace <ns>` filter them. `--values` adds the value per locale.   |
| `x18n search <query>` | Keys found by their value in any locale, best match first, with their usages. `--exact` turns off fuzzy matching.  |
| `x18n get <key>`      | The value in each locale with file and line, the locales that lack the key, the usages and the diagnostics.        |
| `x18n usages [key]`   | The usages of a key, or every usage. `--file <path>` filters by file.                                              |
| `x18n locales`        | The locale codes as found, with display names and resources.                                                       |
| `x18n doctor`         | How x18n understood the project: presets, locale finders, formats, scanners, conflicts, errors and config origins. |

A key glob uses `*` inside one segment and `**` across segments: `x18n keys "pages.**"`.

To find the key behind a text that you see in the app, search the values. The search covers every locale and ignores case. It matches fuzzily, so the letters of the query need to appear in order, but not next to each other. Values that contain the query rank first. `--exact` keeps only those values. Each match lists its usages as `file:line:column`:

```sh
x18n search "sign in"
x18n search "Anmelden" --exact
```

List commands page their output. `--limit <n>` sets the page size. The output ends with a `--cursor` value for the next page, and the JSON output has it as `nextCursor`:

```sh
x18n keys --missing de --limit 50
x18n keys --missing de --limit 50 --cursor 50
```

## Change keys

Do not edit locale files by hand. These commands keep the format, the indent, the key style and the order of each file, and they check placeholders:

| Command                         | Does                                                                                                                             |
| ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `x18n set <key> --value <text>` | Sets one value. `--locale` picks the locale, and the default is the source locale. `--value -` reads stdin.                      |
| `x18n apply <file>`             | Sets many values from JSON: `{ "<locale>": { "<key>": "<value>" } }`. `-` reads stdin.                                           |
| `x18n rename <from> <to>`       | Renames a key in every locale and every usage in code. `--no-usages` keeps the code.                                             |
| `x18n delete <key>`             | Deletes a key in every locale. `--locale` limits it. Code is not changed.                                                        |
| `x18n delete --unused [glob]`   | Deletes every unused key in every locale, except keys that computed keys in code may reach. `--namespace` and the glob limit it. |
| `x18n fill`                     | Adds the missing keys of each locale with empty values. `--copy-source` copies the source value. `--locale` limits it.           |
| `x18n format`                   | Writes the resources again with the configured `write.sort` and `write.indent`.                                                  |

A rename or delete of a parent key changes every key under it. `x18n rename pages screens` moves `pages.home.title` to `screens.home.title`, and updates prefix usages such as ``t(`pages.${id}.title`)``. A rename to a key that exists stops with [X18N4002](https://x18n.dev/errors/x18n4002).

`x18n delete --unused` deletes the keys that `x18n keys --unused` lists, minus the keys in `ignoreKeys`. It also keeps the keys that a fully computed key may reach inside a scope: `t(name)` under `useTranslation('errors')` may reach every key of the `errors` namespace, and under `keyPrefix: 'menu'` every key under `menu`. Run it with `--dry-run` first: it lists each key with its locales and files, then the kept keys with the usages that keep them. A fully computed key outside any scope may reach any key, so the plan warns about it; list the keys it uses in `usage.keysInUse`. Edits happen in place, so comments and formatting stay.

`x18n apply` refuses values whose placeholders differ from the source value, and writes nothing. It lists the rejected values and exits with code 1. Fix them, or pass `--force` to write them anyway.

Every command that writes files accepts `--dry-run`. It prints the changes as a small diff and writes nothing:

```sh
x18n rename app.title app.heading --dry-run
```

```
edit src/locales/de.json
-     "title": "Meine App",
+     "heading": "Meine App",
edit src/locales/en.json
-     "title": "My App",
+     "heading": "My App",
edit src/App.vue
- const title = t('app.title')
+ const title = t('app.heading')
```

If a change needs a decision, such as the file for a new key, x18n asks in a terminal. `--yes` accepts the default answers. See [Plan and decision](https://x18n.dev/guide/concepts#plan-and-decision).

## Review messages

`x18n review` leaves comments, approvals, change requests and suggested values on messages. See [Reviews](https://x18n.dev/guide/reviews).

| Command                                                       | Does                                                                                                                                                                                                                  |
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `x18n review list [key]`                                      | Lists review threads with their state. `--locale` and `--open` filter them.                                                                                                                                           |
| `x18n review comment <key> --locale <l> --text <text>`        | Adds a comment.                                                                                                                                                                                                       |
| `x18n review approve <key> --locale <l>`                      | Approves the current value. `--text` is optional.                                                                                                                                                                     |
| `x18n review approve [glob] --machine`                        | Approves many messages in one plan: a glob, `--namespace`, `--machine`, `--state`, `--thread` or `--from <file>` picks them. See [Approve in batches](https://x18n.dev/guide/machine-translation#approve-in-batches). |
| `x18n review request-change <key> --locale <l> --text <text>` | Asks for a change. The `review-changes-requested` check reports it until someone resolves it or approves.                                                                                                             |
| `x18n review suggest <key> --locale <l> --value <text>`       | Suggests a value, for a human to apply.                                                                                                                                                                               |
| `x18n review resolve <id>`                                    | Marks a comment resolved.                                                                                                                                                                                             |
| `x18n review apply-suggestion <id>`                           | Sets the suggested value and resolves the suggestion.                                                                                                                                                                 |
| `x18n review mark-fresh <key>`                                | Records that the translations of a key are up to date with the source value. `--locale` limits it.                                                                                                                    |

The author is `review.author` from the config, else git `user.name` and `user.email`. `--author "Name <email>"` overrides both.

## Translate messages

`x18n translate --to <locales>` fills in missing messages with the translators of your plugins, checks every result, and marks the values it writes as machine-translated. `--estimate` prints what a run would send, and `--dry-run` translates without writing. `x18n translators` lists the translators. See [Machine translation](https://x18n.dev/guide/machine-translation).

## Extract hard strings

`x18n extract` finds hard-coded strings in source files and turns them into keys. Each candidate has a proposed key, a message and the replacement code.

- `x18n extract --list` prints the candidates.
- In a terminal, `x18n extract` asks for each string: accept the proposed key, type another key, skip it, or stop.
- `x18n extract --yes` extracts every candidate with its proposed key.
- `x18n extract --plan plan.json` writes the candidates to a file. Edit the keys, remove the items that you do not want, then run `x18n extract --apply plan.json`.

Pass files or globs to limit the search: `x18n extract src/components/**`. Files that users never see are never scanned: tests, fixtures, mocks, stories, configs and type declarations, by the conventions of common languages. For example `*.test.ts`, `*_test.go`, `test_*.py`, `*_spec.rb`, `*Test.java`, `*.stories.tsx`, `vite.config.ts`, `*.d.ts`, and directories such as `test/`, `tests/`, `spec/`, `e2e/`, `fixtures/` and `__tests__/`. Control comments, in any comment syntax, skip more:

| Comment                                   | Skips                                                                                   |
| ----------------------------------------- | --------------------------------------------------------------------------------------- |
| `x18n-ignore-file`                        | The whole file, wherever the comment is.                                                |
| `x18n-ignore-start` ... `x18n-ignore-end` | Everything between the two comments. Without an end, everything to the end of the file. |
| `x18n-ignore`                             | Strings on the line of the comment and on the next line.                                |

The same rules apply to the `hard-string` check. The `extract` options of the config set the key style and the strings to ignore. The presets add the replacement code for their library. See [Extraction templates](https://x18n.dev/presets#extraction-templates).

## Global options

| Option             | Effect                                                                     |
| ------------------ | -------------------------------------------------------------------------- |
| `--root <dir>`     | Use `<dir>` as the project root. x18n does not look in parent directories. |
| `--config <file>`  | Use this config file.                                                      |
| `--project <name>` | Work on one project of a monorepo.                                         |
| `--json`           | Print the JSON contract.                                                   |
| `--no-cache`       | Ignore the persistent cache in `node_modules/.cache/x18n`.                 |
| `--yes`            | Accept the default answers of decisions.                                   |

## Output rules

- Results go to stdout. Logs and progress go to stderr, so `x18n keys > keys.txt` works.
- Colors appear only in a terminal. x18n honors `NO_COLOR` and `FORCE_COLOR`.
- With `--json`, stdout is one JSON document, also when the command fails.


## Sitemap

See the full [sitemap](https://x18n.dev/sitemap.md) for all pages.
