GitHub 0
Skip to content
glosslint is in preview and not on npm yet. Version 0.0.1 will be the first release.

x18n integration

Check source locale messages and hard-coded strings with the glosslint x18n plugin and export your corpus to x18n's glossary.

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),
});
x18n.config.ts
OptionDefaultWhat it does
corpusrequiredThe corpus.
sourceLocalethe project's source localeThe locale whose messages are checked.
kindOfnoneDecides a message's kind before glosslint does. See Casing rules.

The plugin registers three checks in x18n:

CheckDefault severityReports
glosslint-termerrorGLOSSLINT_TERM
glosslint-avoidwarningGLOSSLINT_AVOID
glosslint-caseerrorGLOSSLINT_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",
  },
});
x18n.config.ts

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 --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

Section titled "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.
  • 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:

[
  {
    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,
  },
]
ts

See API reference for the toX18nGlossary function and X18nGlossaryEntry type.