Use glosslint/x18n when your project manages translations with 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.
Import toX18nGlossary from glosslint and the plugin from glosslint/x18n, then wire both into 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
Section titled "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. |
Checks
Section titled "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:
export default defineConfig({
plugins: [glosslint({ corpus })],
glossary: toX18nGlossary(corpus),
checks: {
"glosslint-avoid": "error",
},
});Message kinds and fixes
Section titled "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. 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 --fixapplies, exceptcontextterms in messages placed only by shape. - Quick fixes. A
contextcasing 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
Section titled "Exporting your corpus to x18n's glossary"toX18nGlossary(corpus) maps every term in your corpus to an x18n glossary entry:
term,translations, andformsare passed through as written. Definetranslationsandformsper locale on each term as described in Defining terms.notecombines the term'sdescriptionandnuance.doNotTranslate: trueis set on everyexactterm that has notranslations.
For example, given Dock (with German translations and forms) and eBike (case: "exact" with no translations), toX18nGlossary(corpus) produces:
[
{
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 for the toX18nGlossary function and X18nGlossaryEntry type.