Skip to content
Langnostic
Esc
↑↓navigate↵open⌘Jpreview
On this page

Architecture

How the runner and plugins discover, translate, validate, and write content.

Langnostic separates the translation runner from format plugins. The runner loads configuration, resolves files, batches requests, and validates AI output. Plugins interpret file schemas, select pending content, and write results.

See Configuration for a complete setup and Plugin API for a working plugin example.

1. Configuration and discovery

The CLI loads environment variables and searches for langnostic.config.ts, langnostic.config.js, or langnostic.json. For JSON, it validates the configuration version and structure and resolves plugin factory modules from the configuration file’s location. Every format uses named providers and plain AI settings. Langnostic resolves environment references in credentials, headers, parameters, and JSON plugin options, then creates an internal SDK model and a plugin instance for each group before translation.

The runner resolves each group’s source patterns from the CLI’s working directory and substitutes target locales and wildcard captures.

For a source at src/locales/en-US.json and target pattern src/locales/{locale}.json, the resolved metadata has this shape:

{
  "source": {
    "locale": "en-US",
    "path": "src/locales/en-US.json"
  },
  "targets": [
    {
      "locale": "zh-CN",
      "path": "src/locales/zh-CN.json"
    }
  ]
}

Before calling plugins, the runner rejects destination collisions and paths that would overwrite discovered source files. It passes readonly file metadata to each plugin’s trackFiles().

2. Read-only change detection

The runner calls getTranslationStrings() on each plugin. Discovery reads files and plans work without changing them.

  • FormatJS compares IDs. Missing target IDs need translation, obsolete IDs need removal, and edits to source values under existing IDs are not detected.
  • MDX hashes top-level source blocks and frontmatter fields, comparing them with registries and target state. Missing tracking data or mismatched target block counts can cause full content retranslation.

Plugins return TranslationStringArg objects. This is an illustrative argument:

{
  "batchId": "src/locales/en-US.json",
  "id": "welcome",
  "source": {
    "locale": "en-US",
    "string": "Welcome, {username}!",
    "description": "Greeting for a signed-in user"
  },
  "targets": ["zh-CN"]
}

The official plugins use the source file path as batchId. The targets array contains only locales needing this string.

3. Batching, maintenance, and dry runs

The runner groups pending strings by group and batch ID, then chunks each batch by the group’s stringsPerRequest override or the plugin default. For example, 120 strings at 50 per request produce requests of 50, 50, and 20 strings. The global request concurrency defaults to 5.

On real runs, the runner calls each plugin’s optional onTranslationStart() before any AI requests. This hook applies queued maintenance such as removals or reordering. It runs even when no strings need translation.

Dry runs skip maintenance, generation, and result writes. They report pending file batches and string counts rather than individual messages. Maintenance-only changes do not appear as pending AI work; a run can report nothing to translate even when a real run would apply those changes.

4. AI generation and validation

Before each request, the runner gets the plugin’s optional instructions. It sends those instructions and serialized argument objects through AI SDK generateText with an Output.object schema.

The AI output uses translations, and each entry must include its original batchId and id:

{
  "data": [
    {
      "batchId": "src/locales/en-US.json",
      "id": "welcome",
      "translations": [
        {
          "locale": "zh-CN",
          "string": "欢迎,{username}!"
        }
      ]
    }
  ]
}

The runner rejects missing or duplicate entries, unexpected IDs or batches, and missing, duplicate, or unexpected locales. It validates response shape and completeness, not translation quality, ICU syntax, placeholder equivalence, JSX, or unchanged code examples.

5. Plugin result writes

The runner converts AI output into plugin results. Each result retains the input batch, ID, and source, but its targets now contain translated strings:

{
  "batchId": "src/locales/en-US.json",
  "id": "welcome",
  "source": {
    "locale": "en-US",
    "string": "Welcome, {username}!",
    "description": "Greeting for a signed-in user"
  },
  "targets": [
    {
      "locale": "zh-CN",
      "string": "欢迎,{username}!"
    }
  ]
}

After all requests in a batch succeed, the runner calls onTranslationBatchComplete() with the batch’s readonly result array.

The FormatJS plugin merges results into target catalogs. The MDX plugin combines translations with tracked blocks and frontmatter, writes documents, then updates the registry. Official plugins use atomic writes for individual files, not a transaction for the whole batch or run. Maintenance or other completed batches can already have written files when a later request fails.

MDX registry

For docs/en-US/setup.mdx, the registry is docs/en-US/setup.langnostic.json, beside the source. Its schema looks like this (the hashes below are illustrative):

{
  "content": {
    "source": {
      "hashes": ["a1b2c3", "d4e5f6"],
      "locale": "en-US"
    },
    "targets": {
      "zh-CN": ["a1b2c3", "d4e5f6"]
    }
  },
  "frontmatter": {
    "title": "abc123"
  }
}

Target arrays record the source hashes associated with translated blocks, not hashes of translated text. Commit registries with the documents. They do not live in the ignored .langnostic/ debug directory.

6. Completion and failures

The runner waits for requests, reports batch successes and failures, and exits with status 1 if any batch failed. Independent batches can finish despite another batch’s failure. Configuration, discovery, or maintenance failures also fail the command.

Read CLI for debug output and Workflows for review and CI integration.

Plugin contract

The Plugin API reference documents LangnosticPlugin, exported metadata types, pending arguments, completed results, and every lifecycle hook. Use Utilities for building arguments, grouping results, and writing files atomically.

Was this page helpful?