# x18n integration

Use `glosslint/x18n` when your project manages translations with [x18n](https://github.com/x18n-dev/x18n). The plugin checks your source locale's messages and the hard-coded strings x18n finds, and `toX18nGlossary` turns your corpus into x18n's `glossary` so translators and machine translation see the same terms. `@x18n/core` is an optional peer dependency.

## Setup

Import `toX18nGlossary` from `glosslint` and the plugin from `glosslint/x18n`, then wire both into `x18n.config.ts`:

```ts [x18n.config.ts]
// x18n.config.ts
import { defineConfig } from "@x18n/core";
import { toX18nGlossary } from "glosslint";
import glosslint from "glosslint/x18n";
import corpus from "./glosslint.config.ts";

export default defineConfig({
  plugins: [glosslint({ corpus })],
  glossary: toX18nGlossary(corpus),
});
```

## Options

| Option         | Default                     | What it does                                                                 |
| -------------- | --------------------------- | ---------------------------------------------------------------------------- |
| `corpus`       | required                    | The corpus.                                                                  |
| `sourceLocale` | the project's source locale | The locale whose messages are checked.                                       |
| `kindOf`       | none                        | Decides a message's kind before glosslint does. See [Casing rules](https://glosslint.onmax.me/guide/casing). |

## Checks

The plugin registers three checks in x18n:

| Check             | Default severity | Reports           |
| ----------------- | ---------------- | ----------------- |
| `glosslint-term`  | error            | `GLOSSLINT_TERM`  |
| `glosslint-avoid` | warning          | `GLOSSLINT_AVOID` |
| `glosslint-case`  | error            | `GLOSSLINT_CASE`  |

To change a check's severity, override it under `checks` in `x18n.config.ts`:

```ts [x18n.config.ts]
export default defineConfig({
  plugins: [glosslint({ corpus })],
  glossary: toX18nGlossary(corpus),
  checks: {
    "glosslint-avoid": "error",
  },
});
```

## Message kinds and fixes

A message's key decides whether its value is a label, a header, or a sentence, following the rules in [Casing rules](https://glosslint.onmax.me/guide/casing). If the key does not place the message, glosslint falls back to the text's shape. Pass `kindOf` to decide specific keys or files yourself before glosslint runs.

Fixes depend on the finding kind and how the message's kind was decided:

- **Safe fixes.** Spelling and casing findings in messages carry a safe fix that `x18n check --fix` applies, except `context` terms in messages placed only by shape.
- **Quick fixes.** A `context` casing fix in a message placed only by its shape is offered as a quick fix you pick yourself, rather than a safe fix, because the shape guess might be wrong.
- **No fix.** Avoid words and hard-coded strings get no fix. Avoid words need a person to verify the meaning first, and x18n does not edit source files for hard-coded strings outside extraction.

When one message has several safe fixes, each safe fix applies all of them at once, and each finding also keeps a quick fix that changes only its own span.

## Exporting your corpus to x18n's glossary

`toX18nGlossary(corpus)` maps every term in your corpus to an x18n glossary entry:

- `term`, `translations`, and `forms` are passed through as written. Define `translations` and `forms` per locale on each term as described in [Defining terms](https://glosslint.onmax.me/guide/terms).
- `note` combines the term's `description` and `nuance`.
- `doNotTranslate: true` is set on every `exact` term that has no `translations`.

For example, given `Dock` (with German `translations` and `forms`) and `eBike` (`case: "exact"` with no translations), `toX18nGlossary(corpus)` produces:

```ts
[
  {
    term: "Dock",
    translations: { de: "Dock" },
    forms: { de: ["Dockingstation", "Dockingstationen"] },
    note: "A powered stand where one bike is locked. A station is a group of docks.",
  },
  {
    term: "eBike",
    doNotTranslate: true,
  },
]
```

See [API reference](https://glosslint.onmax.me/reference/api) for the `toX18nGlossary` function and `X18nGlossaryEntry` type.

<!-- vitehub-docs:section-links -->
## In this section

- [ESLint](https://glosslint.onmax.me/raw/integrations/eslint.md)
- [x18n](https://glosslint.onmax.me/raw/integrations/x18n.md) (this page)
- [Command line](https://glosslint.onmax.me/raw/integrations/cli.md)

Next: [Command line](https://glosslint.onmax.me/raw/integrations/cli.md)

All pages: [llms.txt](https://glosslint.onmax.me/llms.txt)
