Command-line tool
localize moves translation files between your repository and your project.
It runs on Node.js 20 or newer and uses the REST API.
npm install --save-dev @localize-work/cliSet it up
Section titled “Set it up”-
In the editor, open Project settings → API keys and create a secret key. Give it the permissions for what the CLI will do:
Command Permissions statusRead project pullRead translations pushRead project, Create and edit keys; Write translations to push other languages; Review translations to push them as reviewed publishRead project, Publish releases releasesRead releases syncneeds whatpullneeds, and whatpushneeds for the languages whose files you change. -
Put the key in the
LOCALIZE_API_KEYenvironment variable. The CLI reads it from there only, so the key never sits in a committed file.Terminal window export LOCALIZE_API_KEY=lw_sec_… -
Say where your translation files live:
Terminal window npx localize init --path "locales/{locale}/{namespace}.json"This writes
localize.config.json:{"format": "i18next","path": "locales/{locale}/{namespace}.json"}
The key decides which project the CLI works on. There is no project setting.
Commands
Section titled “Commands”localize pull
Section titled “localize pull”Downloads the project’s current text and writes the files that changed.
npx localize pullnpx localize pull --locale et --locale de --min-status reviewednpx localize pull --dry-runpull exports what is in the editor now, including text that is not published
yet. --min-status reviewed leaves out translations nobody has approved;
source text is always included. To ship exactly what is live, load the
published files instead.
localize push
Section titled “localize push”Uploads translation files. Without options it sends the source language only, which is how new keys from your code reach the editor.
npx localize pushnpx localize push --all-localesnpx localize push --locale et --status reviewed --dry-runMissing keys are created and changed text is updated; nothing is deleted. Text
that a reviewer approved is not replaced unless you push with
--status reviewed. A push runs as an import on the server: the CLI shows its
progress and exits with an error if it fails. While an import is running, the
project accepts no second import and cannot be published.
localize sync
Section titled “localize sync”Merges your files and the project in both directions, text by text, for every language.
npx localize syncnpx localize sync --dry-runnpx localize sync --prefer remote- A text you changed in a file is uploaded. A text someone changed in the editor is written to your file. Each side keeps the other’s changes.
- A text that changed on both sides is a conflict.
synclists it, leaves it as it is on each side, finishes the rest and exits with an error. Run it again with--prefer localto upload yours or--prefer remoteto take the server’s. To choose text by text, first copy the server’s wording into your file for the texts where it should win. - A translation you changed in a file is also held back as a conflict when its
source text changed in the editor since the last sync. It was written
against the earlier source text, and uploading it would mark it as up to
date with the new one.
syncwrites the new source text to your source file; check the translation against it, then runsync --prefer localto upload it. It keeps waiting until you choose a side or put the server’s wording back.--prefer remotetakes the server’s wording for a translation that an earlier run already listed as waiting. One that a run meets for the first time is listed and left alone even with--prefer remote, so nothing in your files is replaced unseen; run it again to take the server’s. Where the server has no translation yet, it leaves yours in the file, and you remove it there if it should not be uploaded. This needs the source language in the same run, sosync --locale eton its own cannot tell. A run that leaves a language out (sync --locale en, orpull --locale en) notes which source texts changed, and the nextsyncwith that language holds its changed translations of them. Apullcan note that only for a language that already had a translation at the last sync. Which texts wait is recorded inlocalize.sync.json, and version 0.1.0 of the CLI does not read that: use 0.1.1 or newer on every machine that syncs. - A text the server does not take stays in your file and is offered again next
time. The usual reason is a translation that a reviewer approved: change it
in the editor, or upload with
--status reviewed. If the reason is that its source text was changed in the editor whilesyncwas uploading, the translation is listed as a conflict instead and waits for your choice. - A file you save while
syncis still running is left as you saved it; runsyncagain to merge it. - A key deleted in the editor is removed from your files. Removing a text from a file does not delete it on the server: it comes back. Delete keys in the editor.
sync knows which side changed from localize.sync.json, which it writes next
to your config file: one short fingerprint per text, taken when the two sides
last agreed. Commit it with your translation files. A checkout without it
has no record of who changed what, so every text that differs is a conflict.
pull keeps the file up to date too, once it exists. push does not: a text
you upload with push and someone then changes in the editor is a conflict at
the next sync. In a project that syncs, upload with sync.
sync reads and writes the same formats as push. It always merges every
text, so it has no --min-status; use pull --min-status reviewed to
download reviewed text only. The state file belongs to one project and one
place for the files (path or dir): sync starts it again, with a warning,
when either is different, and a pull into another folder leaves it alone.
sync reads real files only. If a translation file, or a folder on the way to
it, is a symbolic link, sync stops before changing anything; replace the link
with the file or folder itself.
localize publish
Section titled “localize publish”Publishes every reviewed translation to the CDN. It asks before it does; pass
--yes where nobody can answer, such as CI.
npx localize publish --notes "Autumn campaign copy"localize status and localize releases
Section titled “localize status and localize releases”status prints the project’s languages and how far each is translated.
releases lists recent releases and marks the live one.
Settings
Section titled “Settings”localize.config.json is optional. A flag overrides the file.
| Setting | Flag | Meaning |
|---|---|---|
path |
--path |
Where files live, with {locale} and {namespace} placeholders. |
dir |
--dir |
Instead of path: a folder that receives the format’s default layout. |
format |
--format |
i18next, i18next-flat, icu, icu-flat, android, xcstrings. Default i18next. See export formats. |
namespace |
--namespace |
Work on one namespace. Required when path has no {namespace}. |
apiUrl |
--api-url |
API address. Default https://api.localize.work. |
LOCALIZE_API_URL also sets the API address.
path and dir are relative to the folder of the config file (or the folder
you run the command in). An absolute path works too, if it lies inside that
folder.
Put a / or a . between {locale} and {namespace} in path, as in
{locale}/{namespace}.json or {namespace}.{locale}.json. With a hyphen
between them, a name such as en-GB-common.json can be read two ways. push
and sync go by the languages the project has, and take what follows a
language for a region when it is written like one (GB, 419, Hant): in a
project without en-GB that file is skipped, not read as namespace
GB-common in English.
One file per language
Section titled “One file per language”Some setups keep one file per language, such as messages/en.json for
next-intl. Leave {namespace} out of the path and name the namespace:
{ "format": "icu", "path": "messages/{locale}.json", "namespace": "messages"}Android and iOS
Section titled “Android and iOS”android and xcstrings files can be pulled but not pushed. Use dir so the
files land where the platform expects them. An .xcstrings file holds every
language, so it is pulled whole. A pull that covers only some languages
(--locale, or an API key limited to some languages) is refused, because
writing it would drop the other languages from the file; --allow-partial
writes it anyway.
npx localize pull --format android --dir app/src/main/resnpx localize pull --format xcstrings --dir MyAppUse it in CI
Section titled “Use it in CI”Pull translations during the build so they ship inside the app:
- uses: actions/setup-node@v4 with: node-version: 22- run: npx @localize-work/cli pull --min-status reviewed env: LOCALIZE_API_KEY: ${{ secrets.LOCALIZE_API_KEY }}Push new source strings when they reach your main branch:
on: push: branches: [main] paths: ['locales/en/**']jobs: push: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 22 - run: npx @localize-work/cli push env: LOCALIZE_API_KEY: ${{ secrets.LOCALIZE_API_KEY }}Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 |
The command finished. |
1 |
It failed, or you answered no to publish. The reason is on standard error. |
2 |
publish created the release but it is not live yet; the server keeps retrying. |