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

Quick start

Configure Langnostic for message catalogs and Markdown, then run your first translation.

Prerequisites

  • A supported Node.js version: ^22.18.0, ^24.11.0, or >=26.0.0.
  • Source files in a supported format.
  • An AI provider account and API key. Provider usage charges are separate from Langnostic licensing.

Install the CLI and plugin

For the default OpenAI and FormatJS setup, install both dependencies:

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

Ignore debug output, but keep translation files and MDX registries in version control:

.langnostic/

Initialize configuration

npx langnostic init
pnpm dlx langnostic init
yarn dlx langnostic init
bunx langnostic init
nubx langnostic init
aube dlx langnostic init

For a plain JSON configuration, use npx langnostic init --format json and follow the JSON configuration example.

If no project configuration already exists, this creates the following langnostic.config.ts in your current directory:

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

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

Change the paths to match your project and add target locales as needed. {locale} is replaced with each target locale. For example, adding pt-BR would also generate src/locales/pt-BR.json.

Create the source catalog before translating. A minimal FormatJS catalog is:

{
  "welcome": {
    "defaultMessage": "Welcome, {username}!",
    "description": "Greeting for a signed-in user"
  }
}

The plugin also accepts flat string values. It does not interpret arbitrary nested JSON structures.

Configure your AI provider

Add your key to a .env file in the directory where you run the command:

OPENAI_API_KEY="your-api-key-here"

The CLI loads this file automatically. Keep credentials out of version control.

The examples use the OpenAI provider. Langnostic includes adapters for OpenAI, Anthropic, Google, and OpenAI-compatible endpoints. Set ai.provider and ai.model as plain strings; no provider package installation is needed. The model must support structured translation output.

See AI settings for credentials, custom endpoints, native request parameters, and local servers. Changing the model does not automatically regenerate existing translations.

Translate and review

npx langnostic translate
pnpm dlx langnostic translate
yarn dlx langnostic translate
bunx langnostic translate
nubx langnostic translate
aube dlx langnostic translate

With the generated configuration, this fills missing message IDs in src/locales/zh-CN.json and removes IDs no longer present in the source:

src/
└── locales/
    ├── en-US.json
    └── zh-CN.json

For a repeatable command, add a script to your existing package.json:

{
  "scripts": {
    "translate": "langnostic translate"
  }
}

Then run npm run translate. See Workflows for review and CI integration.

Translate Markdown/MDX

Install the MDX plugin alongside the CLI:

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

For this example, start with docs/en-US/getting-started.mdx. Replace your configuration with this complete Markdown-only setup:

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', 'pt-BR'],
  },
  groups: [
    {
      name: 'docs',
      plugin: MdxPlugin({ frontmatterExcludedKeys: ['slug'] }),
      paths: [
        {
          source: './docs/en-US/**/*.mdx',
          target: './docs/{locale}/**/*.mdx',
        },
      ],
    },
  ],
} satisfies ConfigType;

To translate catalogs and documents together, keep both groups in the groups array, using a separate plugin instance for each group.

Given this source document:

---
title: Getting started
description: Learn how to get started
slug: getting-started
---

# Getting started

Welcome to our documentation!

<Alert>This is an important note.</Alert>

Run langnostic translate to generate both target documents and a registry:

docs/
├── en-US/
│   ├── getting-started.langnostic.json
│   └── getting-started.mdx
├── pt-BR/
│   └── getting-started.mdx
└── zh-CN/
    └── getting-started.mdx

The plugin sends translatable frontmatter and document blocks to the model. frontmatterExcludedKeys keeps fields such as slug out of translation requests. Review the generated frontmatter, Markdown, JSX, and code examples; syntax preservation is model-dependent.

Commit each source document’s *.langnostic.json registry with the source and target files. The registry tracks source hashes and the blocks associated with each target. It is separate from the ignored .langnostic/ debug directory.

Missing registries or changes to a target document’s block count can cause all source blocks to be translated again. See MDX change detection before restructuring translated documents.

Preview pending work

npx langnostic translate --dry-run
pnpm dlx langnostic translate --dry-run
yarn dlx langnostic translate --dry-run
bunx langnostic translate --dry-run
nubx langnostic translate --dry-run
aube dlx langnostic translate --dry-run

The preview shows pending groups, source file paths, and string counts. It does not print individual strings or translated output, make AI requests, or apply file changes. Removal-only or reordering-only maintenance is not listed as pending translation work.

Inspect AI requests

npx langnostic translate --debug
pnpm dlx langnostic translate --debug
yarn dlx langnostic translate --debug
bunx langnostic translate --debug
nubx langnostic translate --debug
aube dlx langnostic translate --debug

Debug runs make real translation requests and write prompts, responses, and errors under .langnostic/runs/. See CLI for flags and exit statuses, and Configuration for all settings.

Was this page helpful?