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

Configuration

Configure AI providers, locales, translation groups, paths, and request limits.

Langnostic supports langnostic.config.ts, langnostic.config.js, and langnostic.json. It searches from the directory where you run the CLI, checking those filenames in that order in each directory. Keep one configuration file per project; the first configuration found is used.

langnostic.config.json is also supported as an alternative JSON filename, with lower precedence than langnostic.json.

AI configuration uses the same named providers and plain data in every format. Use TS/JS for plugin instances or options containing functions. Use JSON for plugin factory references. Langnostic creates its internal AI SDK model before translation; both formats use the same runner and plugin lifecycle.

langnostic init creates a TypeScript configuration. To create langnostic.json:

npx langnostic init --format json

Initialization preserves an existing configuration in any supported format.

JSON configuration

Set version to 1. Model identifiers remain open-ended. This example translates an application catalog and Markdown documents:

{
  "version": 1,
  "ai": {
    "provider": "openai",
    "model": "gpt-6.1-sol"
  },
  "concurrencyLimit": 5,
  "localeConfig": {
    "source": "en-US",
    "target": ["zh-CN"]
  },
  "groups": [
    {
      "name": "app-strings",
      "plugin": "@langnostic/plugin-formatjs",
      "stringsPerRequest": 25,
      "paths": [
        {
          "source": "./src/locales/en-US.json",
          "target": "./src/locales/{locale}.json"
        }
      ]
    },
    {
      "name": "docs",
      "plugin": {
        "module": "@langnostic/plugin-mdx",
        "options": {
          "frontmatterExcludedKeys": ["slug", "date", "tags"]
        }
      },
      "localeConfig": {
        "source": "en-US",
        "target": ["zh-CN", "pt-BR"]
      },
      "paths": [
        {
          "source": "./docs/en-US/**/*.mdx",
          "target": "./docs/{locale}/**/*.mdx"
        }
      ]
    }
  ]
}

Install the referenced plugin packages in your project. Provider adapters are included with Langnostic. Langnostic resolves package exports using ESM resolution from the configuration file’s location. Relative module paths such as ./plugins/custom.mjs are also relative to that file. Installed packages and their versions are managed by your package manager and lockfile.

Plugin factories

A module reference has these fields:

Field Required Behavior
module Yes Installed package, exported package subpath, or local module.
export No Factory export name. Defaults to default.
options No JSON object passed to the factory, including plugin-specific options.

Factories may return their results asynchronously. A plugin factory must return a valid LangnosticPlugin. Each translation group gets a fresh instance. A string such as "@langnostic/plugin-formatjs" is shorthand for a reference to that module’s default factory without options.

Custom plugins use the same reference format:

{
  "plugin": {
    "module": "./plugins/custom.mjs",
    "export": "createPlugin",
    "options": {
      "preserveComments": true
    }
  }
}

For options that contain functions or other executable values, use TS/JS configuration or a local wrapper module that exports a factory.

Environment-variable references

In ai.apiKey, ai.headers, ai.parameters, and plugin options, an object containing only env refers to an environment variable:

{
  "ai": {
    "provider": "openai",
    "model": "gpt-6.1-sol",
    "apiKey": { "env": "MY_OPENAI_API_KEY" },
    "headers": {
      "X-Project": { "env": "PROJECT_ID" }
    },
    "parameters": {
      "metadata": { "project": { "env": "PROJECT_ID" } }
    }
  }
}

References work in nested objects and arrays, and resolve to strings. An unset variable fails configuration loading with its option path. An empty environment variable resolves to an empty string. Strings such as "${MY_OPENAI_API_KEY}" remain literal strings.

The CLI loads .env from its working directory before resolving configuration. You can omit apiKey to use a native provider’s standard environment variable, such as OPENAI_API_KEY. Environment references also work in TS/JS configuration.

TypeScript and JavaScript configuration

Use the exported ConfigType with satisfies to check your configuration. This example translates an application catalog and Markdown documents. Each group owns a separate plugin instance:

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',
  },
  concurrencyLimit: 5,
  localeConfig: {
    source: 'en-US',
    target: ['zh-CN'],
  },
  groups: [
    {
      name: 'app-strings',
      plugin: FormatJSPlugin(),
      stringsPerRequest: 25,
      paths: [
        {
          source: './src/locales/en-US.json',
          target: './src/locales/{locale}.json',
        },
      ],
    },
    {
      name: 'docs',
      plugin: MdxPlugin({ frontmatterExcludedKeys: ['slug', 'date', 'tags'] }),
      localeConfig: {
        source: 'en-US',
        target: ['zh-CN', 'pt-BR'],
      },
      paths: [
        {
          source: './docs/en-US/**/*.mdx',
          target: './docs/{locale}/**/*.mdx',
        },
      ],
    },
  ],
} satisfies ConfigType;

Install each imported plugin separately. Langnostic includes the provider adapters, so consumers do not install or import AI SDK packages. The quick start covers installation and setup. JavaScript uses the same default export with the TypeScript import and satisfies ConfigType annotation removed. AIConfig, AIProvider, EnvironmentReference, DeclarativeConfigType, and ModuleReference are also exported for typed configuration and tools that generate JSON.

Top-level settings

Setting Required Behavior
ai Yes Model and optional generation settings shared by all groups.
localeConfig Yes Default source and target locales, even when groups supply overrides.
groups Yes Array of translation groups. An empty array produces no translation work.
concurrencyLimit No Maximum concurrent AI requests across groups. Defaults to 5.
version JSON only Configuration structure version. Required as 1 in JSON.

concurrencyLimit must be a positive integer. It limits requests, not the number of files, strings, or target locales in a request.

AI settings

Setting Required Behavior
ai.provider Yes openai, anthropic, google, or openai-compatible.
ai.model Yes Freeform, non-empty model ID understood by the endpoint.
ai.apiKey No API key string or an environment-variable reference.
ai.baseURL Compatible only HTTP(S) API base URL, including its version prefix when needed.
ai.headers No Additional request headers, with strings or environment references as values.
ai.parameters No Native API request-body additions, with nested environment references.
ai.temperature No Numeric sampling setting, when supported by the model.
ai.topP No Numeric sampling setting, when supported by the model.

Providers and endpoints

Provider API Default base URL Default API key variable
openai OpenAI Responses https://api.openai.com/v1 OPENAI_API_KEY
anthropic Anthropic Messages https://api.anthropic.com/v1 ANTHROPIC_API_KEY
google Gemini GenerateContent https://generativelanguage.googleapis.com/v1beta GOOGLE_GENERATIVE_AI_API_KEY
openai-compatible OpenAI Chat Completions Required in configuration No default; omit apiKey for unauthenticated servers.

Native providers retain their SDK’s endpoint and credential defaults. For example, the Anthropic adapter also honors ANTHROPIC_BASE_URL. An explicit baseURL overrides the default. Supply the API base, without /responses, /messages, /chat/completions, or the Gemini model path; the adapter appends that path.

Model IDs are passed to the adapter without a Langnostic model catalog. Choose a model that supports structured translation output. OpenAI-compatible endpoints must accept Chat Completions with response_format.type: "json_schema".

An unauthenticated local server needs only these settings:

{
  "ai": {
    "provider": "openai-compatible",
    "model": "your-local-model",
    "baseURL": "http://localhost:1234/v1"
  }
}

For a custom Responses endpoint, use provider: "openai" with its baseURL and credentials. Use openai-compatible for Chat Completions endpoints.

Native request parameters

parameters merges recursively into the serialized API request. Use the native API’s field names and nesting, rather than AI SDK option names. For example:

{
  "ai": {
    "provider": "openai",
    "model": "gpt-6.1-sol",
    "parameters": {
      "reasoning": { "effort": "low" },
      "text": { "verbosity": "low" }
    }
  }
}

For Anthropic, native additions can include thinking and output_config.effort. For Google, use generationConfig, such as {"generationConfig":{"thinkingConfig":{"thinkingBudget":0}}}. The endpoint validates whether a model supports a parameter.

Langnostic preserves the generated model, input, structured-output schema, tool definitions and non-streaming request mode. Attempts to replace those fields, including replacing a schema’s parent object with a scalar or array, are ignored. Other object fields merge recursively; arrays and scalar values replace existing values. Native parameters take precedence over the plain sampling settings if both specify the same request field. Avoid unsupported sampling options on reasoning models. Langnostic supplies no default temperature or topP.

The CLI loads .env from its working directory. Changing models does not regenerate existing translations automatically.

Locale settings

localeConfig contains:

  • source: The source locale, such as en-US.
  • target: A non-empty array of target locales, such as ['zh-CN', 'pt-BR'].

Locale strings must match the supported hyphen-separated locale syntax. Target locales must be unique and different from the source, compared without case sensitivity.

A group’s localeConfig replaces the entire top-level locale configuration for that group. It is not a partial override: provide both source and target.

Translation groups

Setting Required Behavior
name Yes Non-empty identifier, unique across groups, used in progress output.
plugin Yes Plugin instance in TS/JS; factory module reference in JSON.
paths Yes Non-empty array of source/target path mappings.
localeConfig No Complete locale override for this group.
stringsPerRequest No Positive integer overriding the plugin’s batch-size default.

The official FormatJS and MDX plugins default to 50 and 20 strings per request respectively. A string can be a short message, a frontmatter value, or a whole Markdown block; this setting is not a token limit.

Use a new plugin instance for each group so tracked files and options stay independent. See Using plugins for shared setup and the FormatJS and Markdown / MDX references for plugin-specific options and behavior.

Path mappings

Each path mapping has a source pattern and a target pattern. Paths are resolved from the CLI’s working directory, not from the configuration file’s directory.

Use {locale} in the target to insert each configured target locale. The path mapper supports * and **/ wildcard captures, reused in order in the target:

Source Target Example result for zh-CN
./src/locales/en-US.json ./src/locales/{locale}.json ./src/locales/zh-CN.json
./docs/en-US/**/*.mdx ./docs/{locale}/**/*.mdx ./docs/zh-CN/guides/setup.mdx for ./docs/en-US/guides/setup.mdx
./blog/*/en-US.mdx ./blog/*/{locale}.mdx ./blog/welcome/zh-CN.mdx for ./blog/welcome/en-US.mdx

The target cannot contain more wildcard captures than the source. Use matching capture layouts so different source files resolve to different output files.

Source discovery uses glob matching, but target reconstruction only understands the wildcard captures above. Avoid unsupported glob constructs when mapping a matched filename into a target path.

Before plugins run, Langnostic rejects target paths that overwrite any discovered source file or resolve to the same destination more than once, including through symlinks. A source pattern matching no files produces a warning and no work for that mapping; ensure your paths are correct before relying on a successful exit.

Configuration errors

Invalid required fields, locale lists, positive-integer settings, plugin methods, or duplicate group names cause the command to fail. JSON configuration also rejects unsupported versions, unknown top-level fields, invalid module references, missing packages or factory exports, and unset environment references. Configuration and discovery failures exit with status 1.

See CLI for command behavior and Plugin API for the plugin contract.

Was this page helpful?