On this page
sync
sync keeps your translation files and your Locize project in step: it sends the keys of your source language and writes the translations back into your files.
locize sync --path ./locales --format jsonWhat it does
- It reads your files in the source language. A key you added is added in Locize, a key you deleted is deleted in Locize, a namespace file you added is added as a namespace.
- It downloads every language from Locize and writes it into your files, so new translations arrive in your repository.
By default the CLI expects one folder per language and one file per namespace, for example locales/en/common.json. A language in your files that the project does not have yet is created, with an admin key, or with any key that can write while the project is still empty.
With --format android, folders with a region or script carry Android's codes, and the CLI converts them (values-pt-rBR is pt-BR, values-b+sr+Latn is sr-Latn). Strings marked translatable="false" stay in your source file and do not go to Locize; a key an earlier sync sent there is deleted.
Before you run it
- Commit your files: sync writes into them.
- With a folder per language (the default path mask), sync removes each language folder under
--pathwith everything in it and writes it again. Keep only translation files there, or limit the run with--languageor--namespace. - Sync compares your files with the published translations. If the version does not publish automatically, publish it first, or add
--unpublished true. - A changed text of an existing key is not sent. Add
--update-values trueto send it, and--auto-translate trueto have it translated again. - Make all your changes first, then run sync once, not after every single change.
Options
Every option takes a value: --dry true, not --dry.
Files
| Option | What it does | Default |
|---|---|---|
--path | the folder with your translation files | the current folder |
--format | one of the file formats | json |
--path-mask | the layout of folders and files, without file extension | {{language}}/{{namespace}} |
--reference-language-path-mask | a layout of its own for the files of the source language when their names carry no language code, for example Android's values/{{namespace}} next to values-{{language}}/{{namespace}}. If the file name is only {{namespace}}, name the namespaces with --namespace | the path mask |
--language-folder-prefix | text before the language in a folder name | none |
--auto-create-path | creates --path if it is missing | true |
--skip-empty | writes no file for an empty namespace | false |
--clean | removes what the path mask wrote into --path before it writes; refused for the working directory or a repository root, unless the path mask starts with a folder | false |
--clean-local-files | removes all local files, keeps the folders | false |
What it sends
| Option | What it does | Default |
|---|---|---|
--reference-language-only | false also sends the translations you have in your files. Use it for the first import only: later it deletes in Locize the translations your files lack | true |
--review | sends those translations as review proposals; they go live once someone accepts them in the editor. Needs --reference-language-only false and the review workflow on for those languages | false |
--needs-review | writes those translations and marks them as needing review. Needs --reference-language-only false | false |
--update-values | sends changed texts of existing keys | false |
--skip-delete | keeps keys in Locize that you deleted locally | false |
--delete-remote-namespace | deletes a namespace in Locize when you deleted its file in the source language, in every tenant too | false |
--compare-modification-time | when Locize changed a namespace after your file, Locize wins: its keys and texts come into your file instead of yours going to Locize | false |
Translation
| Option | What it does | Default |
|---|---|---|
--auto-translate | true translates new and changed keys with the project's automatic translation; false translates none | new keys, if the project translates automatically |
--auto-translate-review | sends those translations as review proposals, for languages with the review workflow | false |
--auto-translate-languages | translates only into these languages, for example de,fr | all |
What it covers
| Option | What it does | Default |
|---|---|---|
--ver | the version | latest |
--language, --languages | one language, or several separated by commas | all |
--namespace | one namespace, or several separated by commas | all |
--workspace | a workspace of the project, by its name | none |
--changed-only | only the keys that changed on your git branch, for example in a pull request; deletions are skipped | false |
--base | the branch --changed-only compares with | origin/HEAD, then main, then master |
--unpublished | compares with the current translations instead of the published ones | false |
--overridden-only | compares with and downloads only what a tenant or workspace overrides; every other key in your files then looks new and is sent as an override, so use it with files that hold only the overrides | false |
Trying it safely
| Option | What it does | Default |
|---|---|---|
--dry | shows what would change in Locize, and changes nothing; it does not show what it would write into or delete from your files | false |
--backup-deleted-path | saves the keys that sync deletes in Locize into this folder | none |
Plans:
--unpublishedand--overridden-onlycount as private downloads, and so does every file of a version with private publish. Your plan includes them from Growth on.
Examples
Send new keys and have them translated:
locize sync --path ./locales --auto-translate trueSend only the keys of the current branch, for a pull request:
locize sync --path ./locales --changed-only true --auto-translate trueOn a shallow CI clone, fetch the base branch first (in GitHub Actions fetch-depth: 0).
Bring your existing translations into a new project, as review proposals:
locize sync --path ./locales --reference-language-only false --review trueSee what would change:
locize sync --path ./locales --dry true