Skip to content

comvi translate

View .md

Machine-translate every value the project is missing and write the results into the local catalogs. The run pushes your files first, so new source keys are translated too.

Terminal
comvi translate [options]
comvi translate --force-mode keep
🔄 Loading configuration...
🔄 Requesting machine translation...
⏳ Waiting for 2 jobs...
🔄 Fetching translations from TMS...
📝 Writing missing values...
✓ Translate complete!
Pairs: 24 translated, 0 already in flight, 0 filled meanwhile, 1 no source, 40 already translated, 0 failed
Files changed: 2 (24 values)
Option Default Meaning
-c, --config <path> nearest .comvirc.json Config file to read
-l, --locale <locales> locales in config, else every target locale of the project Comma-separated target locales, in any spelling (pt_br is pt-BR). The source locale is never a target. A locale the project does not have exits 4; one the key’s owner may not translate into exits 3
-n, --ns <namespaces> namespaces in config, else all Comma-separated namespaces. The push creates a namespace the project lacks. A namespace still missing when translation starts exits 4; with --no-push, that is any namespace the project does not have
--no-push off Translate what is on the platform without pushing local files first
--force-mode <mode> push.forceMode in config, else ask Conflict handling for the push: override, keep, ask or abort, as in comvi push
--max-keys <n> 1000 Most key × locale pairs one run translates. 0 removes the limit
--dry-run off Count what would be translated and estimate the credits; push, translate and write nothing. With --ns, the platform’s count covers only those namespaces; one the push would create is counted in the push preview line
--timeout <duration> 20m How long to wait for the jobs: 90s, 20m, 1h. A bare number is seconds
--format <format> text json prints one summary object on stdout for scripts. A real run with the push on needs a --force-mode other than ask; a dry run does not

A flag replaces the config value for that run; the two lists never merge.

One run
preflight → push (no auto-MT) → fill → wait for the jobs → fetch → write missing values
  1. Preflight. A read-only call to the platform checks that the key may translate and that the platform has the command. An older platform without it exits 4 before anything is pushed; a key without the mt:use scope exits 3.
  2. Push. Local files go up with the chosen --force-mode, and the push starts no automatic machine translation, whatever the project’s Auto-apply setting. An empty push is not an error. A failed push stops the run with the push’s own exit code.
  3. Fill. The platform counts every key × locale pair whose target is missing and queues machine translation jobs per locale, each holding up to 10,000 keys. Pairs that a running job already covers, from an earlier run or from a push that triggered automatic translation, are reported as in flight and not queued again, so credits are spent once. Results are saved on the platform as Needs Review with the origin machine.
  4. Wait. The CLI polls every job, its own and the ones already in flight, with at most one status request every 2 seconds, backing off to 10 seconds while nothing changes. A terminal shows a progress line. --timeout ends the wait; the jobs keep running on the platform and the run goes on to write what is ready.
  5. Fetch and write. The target locales come down from the platform whatever their status, so human translations made there arrive too. Only keys of the local source catalog are written, and only where the local value is missing: absent or "", and null with --no-push (the push that runs by default rejects a null value). A whitespace-only value is a value.

A non-empty local value is never overwritten. One that differs from the platform’s is counted in the summary: “N differ from the platform; comvi pull will update them”. The rest of each file stays as it is, local-only keys included. A nested file stays nested, a flat file stays flat, and a new file takes the shape of the source file. Files are written as 2-space JSON with a trailing newline, the format comvi pull writes, and each write is atomic. The file is read again right before it is written, so an edit made in that moment is lost: during a run, nothing else should write the same files.

In a nested file, a key that does not fit the structure, nav.home where nav is already a non-empty string, is reported and not written; the run exits 1. A still-empty value whose source is not on the platform is listed with “push first”; --no-push is the usual cause.

comvi translate --max-keys 500
✗ Translate failed: 1240 key × locale pairs to translate (≈1240 credits), over --max-keys 500. No machine translation was started. Raise --max-keys, narrow the run with --locale or --ns, or pass --max-keys 0 for no limit.

--max-keys counts key × locale pairs with new work; pairs already in flight or already translated do not count. A run over the limit starts no machine translation, prints the count and the credit estimate, and exits 4; outside --dry-run and without --no-push, its push has already run. The limit protects a first run on a large project, where one source file and ten locales are ten jobs’ worth of credits.

The estimate is per pair, with the provider’s minimum per request; an AI provider bills by tokens, so its figure is approximate. When the organization’s credits run out during a run, the pairs that were translated are written, the rest are listed, and the run exits 3 with a hint to top up. Running the command again finishes the rest. When credits are already at the limit, nothing new starts; jobs already in flight are still waited for and their values written.

Terminal
comvi translate --dry-run
📊 Translate preview (dry run): nothing is pushed, translated or written
On the platform: 24 pairs, ≈24 credits
Not yet on the platform (would be pushed): ~6 pairs (preview)

The first line is the platform’s count of pairs that exist there today. The second is counted locally from the push preview and the chosen --force-mode: keys whose source is non-empty after the push and whose target is still empty. It carries no credit estimate and is not authoritative; the real run counts again after the push, before any machine translation. The first count over --max-keys exits 4; the two counts together over the limit only warn. --no-push drops the second line.

For a repository that is the source of truth, run the command on main and open a pull request with what it wrote. The pull request review is the human review of the machine translations.

.github/workflows/translate.yml
on:
push:
branches: [main]
paths: ['src/locales/**']
permissions:
contents: write
pull-requests: write
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npx comvi translate --force-mode override
env:
COMVI_API_KEY: ${{ secrets.COMVI_API_KEY }}
- uses: peter-evans/create-pull-request@v7.0.11
with:
branch: comvi/translate
commit-message: 'Add machine translations'
title: 'Machine translations'
body: 'Values filled by `comvi translate`. Review the wording before merging.'

--force-mode override makes the repository win every conflict, so a copy change on main reaches the platform. Translations that already have a value are not redone when their source changes: comvi translate fills only missing values. CI has no terminal, so ask fails there at the first conflict. The default GITHUB_TOKEN opens the pull request only when the repository allows it: Settings → Actions → General → Workflow permissions, “Allow GitHub Actions to create and approve pull requests”. When the pull request merges, the workflow runs again on the merged files, finds nothing to translate, writes nothing, and the action opens no second pull request. A run that exits non-zero fails the job before the pull-request step; the values it did write are still in the workspace.

Turn Auto-apply translations off under Machine translation for a repo-first project. With it on, a comvi push from a developer’s machine translates on the platform right away, outside the workflow and its pull request. comvi translate still collects those values on its next run, but the review happens in one place when the workflow is the only thing that starts machine translation.

Terminal
comvi translate --format json --force-mode keep
{
"version": 1,
"pairs": {
"toTranslate": 24, "alreadyInFlight": 0, "alreadyTranslated": 40, "noSource": 1,
"translated": 24, "filledMeanwhile": 0, "failed": 0, "unfinished": 0,
"unverifiable": 0, "notOnPlatform": 0
},
"jobs": [
{ "jobId": "fill-5-de-5b0c3c1e-8d7a-4c9b-9f61-2f4b8a1d6e30", "targetLocaleCode": "de",
"keyCount": 24, "owned": true, "status": "completed", "processed": 24, "failed": 0 }
],
"written": { "files": 2, "values": 24, "differ": 0 },
"errors": [],
"skippedLocales": [],
"ok": true
}

The object goes to stdout and every progress line to stderr. jobs[].owned is false for a job another run started. jobs[].status is one of completed, failed, running (still running when --timeout ended the wait), gone (the platform no longer has the job), error (its status could not be read) or unverifiable (the platform answered something that is not a status). written counts the files actually written, even when writing others failed, and is false only when none was. errors[] entries carry type and message, plus jobId, locale and key when they apply; a key’s type is the platform’s (insufficient_credits, provider_error, no_translation, unknown).

--dry-run prints { "version": 1, "dryRun": true, "pairs", "estimate", "preview", "jobs": [], "written": false, "errors", "skippedLocales", "ok" }, where pairs holds the platform’s four counters and preview.pairs the count the push would add; with --no-push there is no preview. A run that stops before anything is translated prints pairs: null and one error of type fatal.

The key needs translations:read, translations:write for the push, and mt:use. mt:use is a checkbox labelled Machine translation (uses credits) in the create dialog, off by default and in no preset: it spends the organization’s credits, so every key that has it was given it on purpose. Existing keys do not get it, and the dashboard cannot change a key’s scopes: create a new key. A key without it exits 3 in the preflight, and the message names the scope. See API keys.

One code comes out of everything the run collected, with the precedence 3 > 1 > 2 > 0. Values that were translated are written whatever the code, unless fetching them or writing a file fails, and a run with unfinished jobs ends with “Jobs keep running; run comvi translate again or comvi pull.”

Code Meaning
0 Every requested pair is translated, or there was nothing to translate. A locale skipped because the key’s owner may not translate into it is only a warning
1 A key failed (provider_error, no_translation, unknown), a job failed, the platform answered a job’s status with an error a retry cannot fix (3 when the key was rejected), a locale could not be queued, values are still empty after the jobs ended, a key does not fit its file’s structure, or a file could not be written
2 --timeout ended the wait with values still missing for a locale whose job is running (a job whose status kept failing with a retryable error counts as running), another fill kept the project busy through three attempts, the platform answered a job’s status with something that is not a status, the platform was unreachable, or the fetch of the results failed
3 Credits ran out before or during the run, the key lacks mt:use, a locale named in --locale is one the key’s owner may not translate into, or the key was rejected
4 Invalid flags or config, a namespace or locale the project does not have, a run over --max-keys, or a platform that does not have the command