DocsCLI

CLI commands

Every command, flag and exit code of the generic-translation command line tool.

On this page

The generic-translation CLI extracts messages from your source, sends them for translation, writes locale files and manages projects and keys. The everyday command is generic-translation translate.

Install

The package is @generic-translation/cli and the command it installs is generic-translation. Run npx --package @generic-translation/cli generic-translation to select the scoped package explicitly.

npm install -D @generic-translation/cli      # or: pnpm add -D @generic-translation/cli / yarn add -D @generic-translation/cli
npx generic-translation --help               # once installed, runs the local binary
npx @generic-translation/cli --help          # one-off, without adding it to package.json

Not on npm yet. @generic-translation/cli and the other @generic-translation/* packages have not been published to the npm registry, so the commands above will not work as written until they are. Until then, build the CLI from the Generic Translation repository:

git clone --recurse-submodules https://github.com/generic-translation/generic-translation
cd generic-translation/packages/core && pnpm install && pnpm build
cd ../cli && pnpm install && pnpm build
node dist/cli.js --help          # or: pnpm link --global, then run `generic-translation`

The repository generic-translation-cli also commits action/dist/cli.cjs, a single-file build with every dependency inlined: node cli.cjs --help works with no install at all.

Node 20 or newer is required. @generic-translation/core is bundled, so the package has no Generic Translation runtime dependencies. Where this page writes generic-translation, run whichever of the above you set up.

Global options

Every command accepts these (except where noted, --locales and --default-locale only exist on commands that work with locales).

Flag Meaning
-c, --config <path> Path to generic-translation.config.json. Default: the nearest one, searching upward from the working directory.
--cwd <dir> Run as if started in this directory.
--api-key <key> Project API key or session token. Overrides GENERIC_TRANSLATION_API_KEY and the stored login.
--project-id <id> Project id. Overrides GENERIC_TRANSLATION_PROJECT_ID and the config.
--api-url <url> API base URL. Overrides GENERIC_TRANSLATION_API_URL and the config.
--json Print the machine-readable result as JSON on stdout. Human-readable output moves to stderr.
-l, --locales <codes> Comma-separated target locales (overrides the config).
--default-locale <code> Source locale (overrides the config).

Top-level options on generic-translation itself: -v, --version, --no-color (also honours NO_COLOR), --quiet (only print errors) and -h, --help.

How credentials and the API URL are chosen is described in Configuration.

Exit codes

Code Meaning
0 Success.
1 Validation or extraction problems, or a generic failure.
2 Bad flags, or a missing or invalid config (no target locales, no project selected).
3 Missing or rejected credentials (unauthenticated, permission_missing).
4 The API or the network returned an error.
5 A translation job failed, timed out, or left translations missing.

With --json, a failure also prints { "ok": false, "error": { "message", "code", "hint" } } on stdout.

generic-translation init

Sets up Generic Translation in the current project: detects the framework, writes generic-translation.config.json, optionally creates a project and an API key, and saves credentials to .env.local (adding it to .gitignore).

generic-translation init
generic-translation init --yes --framework vite --locales es,fr,ja
generic-translation init --create-project "My app" --publish
Flag Meaning
-y, --yes Accept detected defaults without prompting (headless).
--force Overwrite an existing generic-translation.config.json.
--framework <id> Skip detection. One of next-app, next-pages, vite, cra, remix, react-router, tanstack-start, react-native, react, vue, node.
--src <globs> Comma-separated source globs.
--output <path> Output template, for example public/_generic-translation/[locale].json.
--dictionary <path> Dictionary JSON file.
--create-project [name] Create a project through the API (needs generic-translation login). Defaults to the package.json name.
--org <id> Organization for --create-project (id or name).
--publish Write "publish": true so generic-translation translate also publishes.
--no-env Do not write .env.local and do not create a project API key.

Plus --locales and --default-locale. Without --locales, targets default to es and fr. Server directories (server/, api/, routes/, src/server/, when they exist) are added to src when the project depends on a Node server framework (Express, Fastify, Hono, Koa, NestJS, h3/Nuxt) or on @generic-translation/node, and .vue is included when Vue or Nuxt is detected. Its closing “next steps” text ends with a one-line reminder that the @generic-translation/* packages are not on npm yet (while that is true); install them from a clone instead (see the introduction).

generic-translation login

Stores a session in ~/.config/generic-translation/credentials.json (or $XDG_CONFIG_HOME/generic-translation/, or $GENERIC_TRANSLATION_CONFIG_DIR), file mode 0600.

generic-translation login --email ada@example.com        # password is prompted
generic-translation login --signup --name "Ada" --email ada@example.com
generic-translation login --token gt-sess-…              # store an existing session token
Flag Meaning
--email <email> Account email (or GENERIC_TRANSLATION_EMAIL).
--password <password> Account password (or GENERIC_TRANSLATION_PASSWORD); prompted when omitted.
--token <token> Verify and store an existing session token instead of logging in.
--signup Create an account instead of logging in.
--name <name> Display name for --signup (default: the part of the email before @).

generic-translation logout

Ends the stored session on the server (best effort) and deletes the local credentials file.

generic-translation whoami

Shows which credentials are in use (flag, environment or stored session), the API URL, and who they belong to: the user and organizations for a session, or the project for a project API key.

generic-translation extract

Alias: generate. Scans your sources and writes the source-locale message map (hash -> source) to the output path for the default locale. Makes no API calls.

generic-translation extract
generic-translation extract --dry-run
generic-translation extract -o messages.json
Flag Meaning
--dry-run Report what would be written without touching the filesystem.
--ignore-errors Skip messages that fail extraction instead of exiting with code 1.
-o, --out <path> Write here instead of the configured output. A path containing [locale] replaces the template; a literal path writes one file.

generic-translation validate

Alias: lint. Checks the messages in your source and any locale files already on disk. Intended for CI. Makes no API calls.

generic-translation validate
generic-translation validate --strict
generic-translation validate --json

It reports extraction diagnostics (see diagnostic codes), then checks every configured locale file: it must be a JSON object of hash -> string, each translation must be valid ICU, and it must use the same variables and tags as its source (incompatible_translation). Translations whose hash is no longer used in source are warnings (unknown_hash). Coverage is printed per locale.

Flag Meaning
--strict Also fail on warnings and on untranslated messages.

Exit code is 1 when there are errors (or, with --strict, warnings or missing translations).

Diagnostic codes

Code Severity Meaning
parse_error error The file could not be parsed as JavaScript/TypeScript/JSX.
non_literal_child error A {expression} or spread directly inside <T>; wrap it in <Var>.
dynamic_t_argument error The first argument of t() is not a string literal.
dynamic_context error $context or context is not a string literal (it is part of the hash).
dynamic_prop warning or error A prop that must be literal is dynamic, or spread props on <Branch>.
invalid_icu error The message is not valid ICU MessageFormat.
invalid_dictionary error The dictionary file is missing or malformed.
missing_prop warning For example <Plural> without n, <Branch> without branch, <Currency> without currency.
missing_value warning t() uses {name} but no such value is passed.
unknown_dictionary_id warning d("id") refers to an id absent from the dictionary.
nested_t warning <T> inside <T> is treated as a plain element.
empty_message warning <T> has no translatable content.
duplicate_id warning The same id is used for two different messages.
invalid_translation error A translation in a locale file is not valid ICU.
incompatible_translation error A translation’s variables or tags differ from its source.
unknown_hash warning A locale file has an entry no source message uses.
invalid_locale_file error A locale file is not a JSON object of strings.

What gets extracted

Imports are recognised from @generic-translation/react (and its subpaths such as @generic-translation/react/next and @generic-translation/react/server), @generic-translation/react-native, @generic-translation/tanstack-start, @generic-translation/vue and @generic-translation/node, including their subpaths. @generic-translation/react-native and @generic-translation/tanstack-start re-export the React surface, so they are handled exactly like @generic-translation/react. Aliases (import { T as Trans }), namespace imports and CommonJS require destructuring work. A component named T imported from somewhere else is ignored.

Files that match src are scanned: .ts .tsx .js .jsx .mjs .cjs with Babel, and .vue single-file components. Every message hashes exactly as the matching runtime does at run time.

<T>, t() and dictionaries

<T> children are converted to a message the same way the runtime does it; anything that cannot be known at build time is an error (non_literal_child). const t = useGenericTranslation() or const t = await getGenericTranslation() gives you t("..."), whose first argument must be a string literal, a template literal without substitutions, or a concatenation of literals. $context must be a literal too. d("nav.home") calls on useDictionary() / getDictionary() are checked against the dictionary file.

@generic-translation/node

Code Extracted
const t = await getGenericTranslation() or getGenericTranslation("es") t("...", { $context, $id }) calls, and t.resolve("...")
msg("...", { context, id }) The descriptor’s message. t(DESCRIPTOR) is then not an error, also when the descriptor is imported or a member such as MESSAGES.subject.
getDictionary() d("id") calls are checked against the dictionary file.
req.t("...") / request.t("...") (genericTranslationExpress, genericTranslationFastify), const { t } = req, Hono c.get("t")("...") t calls. Enabled only in files that import something from @generic-translation/node (a type-only import counts), because .t is too generic a name to extract everywhere.
withRequestLocale(req, (t, locale) => ...) The callback’s first parameter is a t.
tx(text) Nothing. It translates arbitrary runtime text, so it is runtime-only and never extracted.

Vue single-file components

  • <script> and <script setup> blocks (lang of js, ts, jsx or tsx) are extracted like any other module.
  • Template expressions are extracted as t() calls: interpolations ({{ t("Save") }}), bindings (:title="t('Save')", v-text), event handlers and dynamic directive arguments. t is any top-level useGenericTranslation() binding of <script setup>, t when the component imports from @generic-translation/vue (Options API setup() returning t), and the global $t. Because }} ends a Vue interpolation, put ICU plurals such as {count, plural, ... {# items}} in an attribute binding (v-text="t('...')") or in the script.
  • <T> in templates follows the serialization rules on the @generic-translation/vue reference. Generic Translation components are recognised by their exact PascalCase name or by a local name imported from @generic-translation/vue.

Limitations

  • A t that is shadowed inside a template, for example by a v-for variable or a slot prop named t, is not tracked: the CLI still treats it as the translation function.
  • Vue templates with lang="pug" (or any non-HTML lang) are not scanned.
  • In Vue templates, {{ ... }} outside Var-style content, comments, v-if / v-for / key, <slot>, <pre> / <textarea> / v-pre, named slots on other elements, dynamic slot names, v-bind="object" on Plural / Branch, and non-literal name / currency / context / branch attributes inside <T> are reported with file:line:col, and that <T> is skipped.
  • Strings built at run time (variables, interpolated template literals) cannot be extracted; use runtime translation or declare them with msg().

generic-translation translate

The command you normally need. It extracts messages, submits those the lock file says are new, waits for the jobs, downloads the results and writes one JSON file per locale. If a files section is configured it also uploads, translates and writes those files. Optionally publishes to the CDN afterwards.

generic-translation translate
generic-translation translate --locales es,de --publish
generic-translation translate --dry-run
Flag Meaning
--dry-run Show what would be sent without calling the API or writing files.
--force Ignore the lock file and ask the API to re-translate everything.
--branch <name> Branch to store translations under. Default: the detected branch.
--ignore-errors Continue past extraction errors and failed translations.
--no-files Skip the files section of the config.
--publish / --no-publish Publish to the CDN afterwards, or not, overriding publish in the config.
--timeout <seconds> How long to wait for translation jobs. Default 600.

It exits with 5 if translations are still missing after the jobs finish (unless --ignore-errors). Needs an API key or session with translations:enqueue (and translations:write for --publish).

Branches

When --branch is not given, the branch comes from CI variables first (GITHUB_HEAD_REF, GITHUB_REF_NAME, CI_COMMIT_REF_NAME, VERCEL_GIT_COMMIT_REF), then git rev-parse --abbrev-ref HEAD. If neither works, the API’s default branch (main) is used.

generic-translation upload

Extracts and submits for translation without waiting. Prints the job ids, then exits. Accepts the same flags as translate that apply to submitting: --dry-run, --force, --branch, --ignore-errors, --no-files, plus the global options.

generic-translation upload
generic-translation status job_… --watch
generic-translation download --job job_…

generic-translation status

generic-translation status [jobId]. With a job id, shows that job; without, shows project stats (strings, files, per-locale coverage) and recent jobs.

Flag Meaning
-w, --watch Wait until the job finishes.
--timeout <seconds> How long --watch waits. Default 600.
--limit <n> Number of recent jobs to list. Default 10.

Exits 5 if the job failed.

generic-translation download

Downloads translations and writes locale files, without submitting anything.

Flag Meaning
--job <id> Wait for this job first. Repeatable.
--all Write every translation the project has, not only messages found in your source.
--branch <name> Branch to read from. Default: the detected branch.
--timeout <seconds> How long to wait for --job. Default 600.
--ignore-errors Write what is available even if a job failed.
--no-files Skip the files section.

generic-translation publish

Publishes the latest translations to the CDN (POST /v1/projects/:id/publish). Needs translations:write. See Publishing and the CDN.

generic-translation publish

It accepts --locales, which the current implementation treats as “publish the configured locales” (the codes you pass are not used individually); without the flag the server publishes its default set.

generic-translation configure

Alias: config. Shows or edits generic-translation.config.json. Run without flags in a terminal, it prompts for each field; non-interactively it prints the config.

generic-translation configure --show
generic-translation configure --add-locale ja,ko
generic-translation configure --remove-locale fr --publish
Flag Meaning
--show Print the current config and exit.
--add-locale <codes> Add target locales.
--remove-locale <codes> Remove target locales.
--src <globs> Comma-separated source globs.
--output <path> Output template containing [locale].
--dictionary <path> Dictionary file.
--publish / --no-publish Set publish.
--base-url <url> Store an API base URL.

The edited file is validated before it is written. --project-id, --default-locale and --locales also write to the file here.

generic-translation keys

Manage project API keys. Needs a user session, not a project key. See API keys and permissions.

Command Meaning
generic-translation keys create Create a key, shown once. Flags: -n, --name <name> (default CLI key), -p, --permissions <list> (comma-separated; default is the API’s default set).
generic-translation keys list (ls) List the project’s keys.
generic-translation keys revoke <keyId> (rm) Revoke a key.
generic-translation keys create --name "CI" --permissions translations:enqueue,translations:write

generic-translation projects

Command Meaning
generic-translation projects list (ls) List projects you can access. --org <id> limits to one organization. With a project key it shows that key’s project.
generic-translation projects create <name> Create a project (needs generic-translation login). Flags: --org <id> (id or name; default: your first organization), --save (write the new id to generic-translation.config.json). The configured default and target locales are used.

generic-translation locales

Lists the common supported locales with English and native names.

Flag Meaning
-s, --search <text> Filter by code or name.
--configured Only the locales in your config.

Any valid BCP 47 code works, not just the listed ones. See also the supported locales page.

generic-translation api

generic-translation api <method> <path> sends an authenticated request and prints the JSON response; the escape hatch for any REST route.

Flag Meaning
-d, --data <json> Request body: inline JSON, @file to read a file, or - for stdin.
-q, --query <key=value> Query parameter. Repeatable.

:projectId in the path expands to the selected project.

generic-translation api GET /v1/me
generic-translation api GET /v1/projects/:projectId/stats
generic-translation api PUT /v1/projects/:projectId/context --data '{"instructions":"Friendly, concise."}'

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

Type to search the documentation.