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

Using plugins

Install format plugins, configure translation groups, and review generated translations.

Plugins read your file formats, identify pending content, provide translation instructions, and write translated files. The CLI handles source discovery, AI requests, batching, and progress reporting.

The official plugins support FormatJS catalogs and Markdown/MDX documents.

Install plugins

Install the CLI and the plugins for the formats you use. This example uses OpenAI and both official plugins:

npm install langnostic @langnostic/plugin-formatjs @langnostic/plugin-mdx -D
pnpm add langnostic @langnostic/plugin-formatjs @langnostic/plugin-mdx -D
yarn add langnostic @langnostic/plugin-formatjs @langnostic/plugin-mdx -D
bun add langnostic @langnostic/plugin-formatjs @langnostic/plugin-mdx -D
nub add langnostic @langnostic/plugin-formatjs @langnostic/plugin-mdx -D
aube add langnostic @langnostic/plugin-formatjs @langnostic/plugin-mdx -D

Langnostic includes provider adapters. Install plugins separately and make provider credentials available before translating; the OpenAI provider reads OPENAI_API_KEY from the environment or your project’s .env file.

Configure translation groups

Import each plugin’s default factory and assign a new instance to each group. This configuration translates a message catalog and MDX documents:

import FormatJSPlugin from '@langnostic/plugin-formatjs';
import MdxPlugin from '@langnostic/plugin-mdx';
import type { ConfigType } from 'langnostic';

export default {
  ai: {
    provider: 'openai',
    model: 'gpt-6.1-sol',
  },
  localeConfig: {
    source: 'en-US',
    target: ['zh-CN'],
  },
  groups: [
    {
      name: 'app-strings',
      plugin: FormatJSPlugin(),
      paths: [
        {
          source: './src/locales/en-US.json',
          target: './src/locales/{locale}.json',
        },
      ],
    },
    {
      name: 'docs',
      plugin: MdxPlugin(),
      paths: [
        {
          source: './docs/en-US/**/*.mdx',
          target: './docs/{locale}/**/*.mdx',
        },
      ],
    },
  ],
} satisfies ConfigType;

Each factory returns a LangnosticPlugin. A plugin instance stores its group’s tracked files and options, so create a separate instance for every group, even when several groups use the same format.

JSON configuration

In langnostic.json, reference each plugin’s factory module. Use a string for its default factory without options, or an object to supply options:

{
  "groups": [
    {
      "name": "docs",
      "plugin": {
        "module": "@langnostic/plugin-mdx",
        "options": {
          "frontmatterExcludedKeys": ["slug", "date", "tags"]
        }
      },
      "paths": [
        {
          "source": "./docs/en-US/**/*.mdx",
          "target": "./docs/{locale}/**/*.mdx"
        }
      ]
    }
  ]
}

For FormatJS, "plugin": "@langnostic/plugin-formatjs" is sufficient. Package names and local modules are resolved from the configuration file’s location. Use export to select a named factory. Each group receives a new plugin instance, including when groups reference the same module. See the complete JSON example for required top-level fields, provider configuration, and environment references.

Pass format-specific options to the factory. Put paths, localeConfig, and stringsPerRequest on the group. See Configuration for all group fields.

Paths and locales

Set the default source and target locales in the top-level localeConfig. A group can supply a complete locale override with its own source and target.

Paths are resolved from the directory where you run the CLI. Use {locale} in the target pattern for each target locale, and matching wildcard captures to retain source subdirectories or filenames. The CLI resolves these paths before passing file metadata to the plugin.

See path mappings for supported patterns and destination validation.

Batching and concurrency

Plugins supply a default number of strings per request: 50 for FormatJS and 20 for Markdown/MDX. Set a positive integer stringsPerRequest on a group to override its plugin’s default. This counts strings, not tokens or files; an MDX string can be a whole document block.

The top-level concurrencyLimit controls concurrent AI requests across groups and defaults to 5. See Configuration for settings.

Run and review

Preview pending file batches and string counts, then translate:

npx langnostic translate --dry-run
npx langnostic translate

A dry run makes no AI requests or file changes. It does not preview individual strings or list maintenance-only changes such as removed IDs or reordered blocks.

Review the generated diff and validate messages, placeholders, Markdown, JSX, and code examples with your application’s tooling. Commit translated documents with their MDX registries, and keep .langnostic/ debug output out of version control. See Workflows for review, retries, and CI integration.

Official plugins

FormatJS plugin

The FormatJS reference describes flat JSON string maps and descriptors with defaultMessage and description.

Its change detection fills missing target IDs and removes obsolete IDs. Source edits under an existing ID do not trigger retranslation.

Markdown/MDX plugin

The Markdown / MDX reference covers both extensions and options for excluding frontmatter fields from AI requests.

Read MDX change detection for registry requirements, structural edits, and cases that trigger full retranslation.

The syntax guidance explains model-dependent preservation and formatting changes.

Custom plugins

Implement LangnosticPlugin to add a format. The Plugin API reference documents exported types, hook signatures, argument and result shapes, and a complete plain-text plugin.

Lifecycle and writes

Discovery must leave files unchanged. Queue maintenance for onTranslationStart() and write translated results in onTranslationBatchComplete(). See the hook reference for call order, concurrency, and failure behavior, and Utilities for normalization and atomic write helpers.

Was this page helpful?