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 glossary into x18n's glossary so translators and machine translation see the same terms. @x18n/core is an optional peer dependency.
Load .agents/glossary.md with fromGlossary(), pass it to the plugin from glosslint/x18n, and export it with toX18nGlossary in x18n.config.ts:
import { defineConfig } from "@x18n/core";
import { fromGlossary, toX18nGlossary } from "glosslint";
import glosslint from "glosslint/x18n";
const corpus = fromGlossary();
export default defineConfig({
plugins: [glosslint({ corpus })],
glossary: toX18nGlossary(corpus),
});If you keep your glossary at another path, pass it to fromGlossary(new URL("./docs/glossary.md", import.meta.url)). Per-locale translations and forms go in the glossary's Translations and Forms fields:
## Dock
What: A powered stand where one bike is locked.
Translations: de: Dock
Forms:
- de: Dockingstation, DockingstationenOptions
Section titled "Options"| Option | Default | What it does |
|---|---|---|
glossary | .agents/glossary.md | The glossary file to read, as a path from the current folder or a URL. |
corpus | none | A corpus to use instead of a file, such as one from defineCorpus. Not with glossary. |
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. |
With no glossary or corpus, glosslint() reads .agents/glossary.md once, when the config loads. The setup above passes corpus because toX18nGlossary needs the same terms. Passing both throws GLOSSLINT_C012.
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 each of your own terms to an x18n glossary entry. The terms that Presets: tech, inclusive or extends: [tech] add are left out, so translators get your glossary and not hundreds of product names; a term of your own with a preset term's name is kept:
term,translations, andformscome from the glossary'sTranslationsandFormsfields or fromdefineCorpus. A locale that sayskeeporkeep (gloss)gets the term itself as its translation, a baretranslategets none, and`/pattern/`forms andHintsare left out, since x18n's glossary has no place for them.notecombines the term'sdescriptionandnuance. Pass{ note: "short" }for thedescriptionalone, the glossary'sWhat, when translators want a note that fits on one line. A gloss is added after it asfr: keep, gloss as "couche".doNotTranslate: trueis set on everyexactterm whoseTranslationsitems all keep the term, or that has none.
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.
Merging into a shared glossary YAML
Section titled "Merging into a shared glossary YAML"When translators keep an x18n glossary in YAML, such as a glossary.yml shared by several repositories, glosslint export --merge adds your glossary to it without dropping their work:
npx glosslint export --note short --merge ../translations/glossary.yml- An entry matches one in the file when they share the term or one of its source-locale
forms, in any case and with hyphens and spaces ignored. "Prerendering" matchesprerendering, and a termPrerenderwith the formprerenderingmatches it too. Other punctuation counts, soC#doesn't matchC++. A term goes to the entry with the same term before any form is compared, soRenderwith the formRenderinggoes toRenderwhen the file has both. A term that matches more than one entry, or two terms that match the same entry, stop the merge before anything is written, and the command names them.--source-localenames the locale of those forms (defaulten). - A matched entry keeps its
term, itstranslationsand every field glosslint does not write. glosslint setsnote, adds translations and forms for locales the entry lacks, and setsdoNotTranslateonly on entries with no translations. A term withTranslationswhose entry hasdoNotTranslate: truestops the merge, since x18n would never translate it, and the command names the entry and the flag to remove. A locale that keeps the term agrees with the flag, so it is skipped instead. A translation the file already has wins over the glossary's, and the command lists each one it kept. - Terms with no match are added at the end. Comments, entry order and the formatting of the entries it does not touch stay as they are.
Without --merge, glosslint export prints the entries as YAML. See Command line.
Exporting a locale to diglot
Section titled "Exporting a locale to diglot"diglot keeps one glossary per locale, such as fr/glossary.yml, whose entries replace the shared x18n entries with the same term and can say more: a decision, the patterns a translation may also be written as, and a match pattern for the term in the source. glosslint export --diglot <locale> writes that file from the locale's items in Translations, Forms and Hints:
npx glosslint export --diglot fr --merge ../translations/fr/glossary.ymlOnly the terms with an item for the locale in Translations are exported, so a Case: exact term without one stays in the shared x18n file. Given the example glossary, where Dock has fr: borne, the form fr: bornes and the hint fr: Feminine: la borne., and Week Pass (WP) has fr: keep (abonnement hebdomadaire), glosslint export --diglot fr prints:
terms:
- term: Week Pass
match: \b(?:weekly[- ]?tickets|weekly[- ]?ticket|Week[- ]?Passing|Week[- ]?Passed|Week[- ]?Passes|Week[- ]?Pass|WPs|WP)\b
decision: keep-gloss
gloss: abonnement hebdomadaire
- term: Dock
match: \b(?:Docking|Docked|Docks|racks|bays|Dock|rack|bay)\b
note: "Feminine: la borne."
decision: translate
target: borne
accept:
- bornesdecisioniskeep,keep-glosswith thegloss, ortranslatewith the translation astarget, or notargetfor a baretranslate.acceptlists the locale'sForms, escaped, and its`/pattern/`forms as they are. A form in backticks loses them before it is escaped. It is written only fortranslate.noteis the locale'sHintsitem.matchfinds the term in the source: the term, its abbreviations, its source-localeFormsand itsAvoidwords, with their plurals andedandingforms, longest first, as whole words. A space or hyphen inside a word is optional.caseSensitive: trueis set onCase: exactterms only.
--merge <file> writes into the locale's diglot glossary in place, matching entries as the x18n merge does, by term and then by source-locale form, and keeping the file's spelling of term. glosslint owns decision, target, gloss and accept, and note when the term has a hint. It adds accept patterns the entry lacks and removes none. The file keeps its own match and caseSensitive, or its lack of them, its note when the term has no hint, every other key, style, comments and order. Entries the glossary doesn't have stay, and new terms are added at the end with the generated match and caseSensitive. A file with CRLF line endings keeps them. A second merge changes no byte. The command prints what changed:
fr/glossary.yml: 2 terms merged, 1 added, 1 updated, 0 unchanged, 1 kept `match`.
+ Week Pass
~ dock: note, decision (was keep), target, acceptkept `match` counts the entries whose own match differs from the one glosslint generates; the file's stays. A missing locale or one that is not a BCP 47 tag, a locale no term has, a merge file that is missing, isn't valid YAML or is an x18n list, a term that matches two entries, or two terms that match one entry exit 2 and write nothing.