DocsCLI

Configuration

The generic-translation.config.json reference, environment variables, and how the CLI resolves credentials.

On this page

The CLI and the build-time tooling read generic-translation.config.json from your project root. generic-translation init writes one; every field is optional.

{
  "projectId": "prj_…",
  "baseUrl": "https://generic-translation-api.jacobfv123.workers.dev",
  "defaultLocale": "en",
  "locales": ["es", "fr", "ja"],
  "src": ["src/**/*.{ts,tsx,js,jsx}", "app/**/*.{ts,tsx,js,jsx}"],
  "dictionary": "dictionary.json",
  "output": "public/_generic-translation/[locale].json",
  "publish": false,
  "files": {
    "json": { "include": ["locales/[locale]/*.json"] },
    "md": { "include": ["docs/[locale]/**/*.md"], "exclude": ["docs/[locale]/drafts/**"] }
  }
}

Unknown fields are rejected, and the CLI lists every problem at once with exit code 2. The file is found by walking up from the working directory (or use -c). All relative paths resolve against the directory that contains the config file.

Fields

Field Type Default Meaning
$schema string none Accepted and kept, for editors.
projectId string none Project id (prj_…). Overridden by GENERIC_TRANSLATION_PROJECT_ID and --project-id. With a project API key and no id, the literal current is used.
baseUrl string https://generic-translation-api.jacobfv123.workers.dev API origin (must be http(s); trailing slashes removed). Set this when self-hosting. Overridden by GENERIC_TRANSLATION_API_URL and --api-url.
defaultLocale string en Source locale of your app. Standardized (en_us becomes en-US) and validated.
locales string[] [] Target locales. Standardized, de-duplicated, and the default locale is removed. translate, upload and download need at least one.
src string[] ["src/**/*.{ts,tsx,js,jsx}", "app/**/*.{ts,tsx,js,jsx}"] Globs of source files to scan. A single string is accepted. node_modules, dist, build, .next, .git and *.d.ts are always ignored.
dictionary string none Path to a dictionary JSON file (nested object whose leaves are "message" or ["message", { "context": "…" }]).
output string public/_generic-translation/[locale].json Where locale files are written. Must contain [locale].
publish boolean false Publish to the CDN after each generic-translation translate.
files object none File translation groups, see below.

generic-translation init picks different defaults for src and output per framework (for example locales/[locale].json for Node), based on your package.json and directory layout.

Output files

For each locale, generic-translation translate writes one JSON file at output with [locale] replaced. The file is a translation map: { "<hash>": "<translated ICU string>" }, keys sorted, two-space indentation, trailing newline. A file is only rewritten when its content changes. The default locale’s file maps each hash to the source text.

Files

files translates whole documents and resource files with the API’s file pipeline. Keys are formats: json, yaml, md, mdx, txt, html, srt, po, strings, androidxml, resx, xliff, csv. A few aliases are accepted (yml, markdown, text, htm, xlf, xml for androidxml).

Each group has:

  • include (required, non-empty): glob patterns that must contain [locale].
  • exclude (optional): glob patterns to skip.

[locale] is replaced by the default locale to find sources, and by each target locale to compute output paths. Only the placeholder positions are substituted: with docs/[locale]/**/*.md, the source docs/en/guide/en-route.md becomes docs/es/guide/en-route.md.

"files": {
  "json": { "include": ["locales/[locale]/*.json", "src/i18n/[locale].json"] },
  "po":   { "include": ["po/[locale]/messages.po"] }
}

Source files are uploaded when their content changes (tracked in the lock file), translated, and downloaded to the computed paths. Use --no-files to skip them.

Environment variables

Variable Used for
GENERIC_TRANSLATION_API_KEY Project API key (gt-api-…) or session token (gt-sess-…).
GENERIC_TRANSLATION_PROJECT_ID Project id.
GENERIC_TRANSLATION_API_URL API base URL.
GENERIC_TRANSLATION_EMAIL, GENERIC_TRANSLATION_PASSWORD Non-interactive generic-translation login.
GENERIC_TRANSLATION_CONFIG_DIR Where the stored session lives (default $XDG_CONFIG_HOME/generic-translation, else ~/.config/generic-translation).
GENERIC_TRANSLATION_POLL_INTERVAL_MS Job polling interval, default 1500.
NO_COLOR Disable colored output.
GITHUB_HEAD_REF, GITHUB_REF_NAME, CI_COMMIT_REF_NAME, VERCEL_GIT_COMMIT_REF Read to detect the branch.

The CLI reads variables from the real environment first, then .env.local, then .env, looking in the config directory and the working directory. The libraries read the same names; see Node reference.

Credentials resolution

Credentials are chosen in this order:

  1. --api-key
  2. GENERIC_TRANSLATION_API_KEY (shell, then .env.local, then .env)
  3. the session saved by generic-translation login

A token starting with gt-sess- is treated as a user session; anything else is a project API key. Project keys only work on their own project and cannot create projects or keys; user sessions can. The project is chosen from --project-id, then GENERIC_TRANSLATION_PROJECT_ID, then projectId; a project key with none of those uses current.

The API URL is chosen from --api-url, then GENERIC_TRANSLATION_API_URL, then baseUrl, then the default.

Keep keys out of version control. generic-translation init writes GENERIC_TRANSLATION_API_KEY to .env.local (mode 0600) and adds that file to .gitignore. Never put an API key in a browser bundle; see API keys and permissions.

Something wrong or unclear on this page? Open an issue.

Type to search the documentation.