Skip to content
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.

bash
locize sync --path ./locales --format json

What it does

  1. 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.
  2. 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 --path with everything in it and writes it again. Keep only translation files there, or limit the run with --language or --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 true to send it, and --auto-translate true to 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

OptionWhat it doesDefault
--paththe folder with your translation filesthe current folder
--formatone of the file formatsjson
--path-maskthe layout of folders and files, without file extension{{language}}/{{namespace}}
--reference-language-path-maska 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 --namespacethe path mask
--language-folder-prefixtext before the language in a folder namenone
--auto-create-pathcreates --path if it is missingtrue
--skip-emptywrites no file for an empty namespacefalse
--cleanremoves 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 folderfalse
--clean-local-filesremoves all local files, keeps the foldersfalse

What it sends

OptionWhat it doesDefault
--reference-language-onlyfalse 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 lacktrue
--reviewsends 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 languagesfalse
--needs-reviewwrites those translations and marks them as needing review. Needs --reference-language-only falsefalse
--update-valuessends changed texts of existing keysfalse
--skip-deletekeeps keys in Locize that you deleted locallyfalse
--delete-remote-namespacedeletes a namespace in Locize when you deleted its file in the source language, in every tenant toofalse
--compare-modification-timewhen Locize changed a namespace after your file, Locize wins: its keys and texts come into your file instead of yours going to Locizefalse

Translation

OptionWhat it doesDefault
--auto-translatetrue translates new and changed keys with the project's automatic translation; false translates nonenew keys, if the project translates automatically
--auto-translate-reviewsends those translations as review proposals, for languages with the review workflowfalse
--auto-translate-languagestranslates only into these languages, for example de,frall

What it covers

OptionWhat it doesDefault
--verthe versionlatest
--language, --languagesone language, or several separated by commasall
--namespaceone namespace, or several separated by commasall
--workspacea workspace of the project, by its namenone
--changed-onlyonly the keys that changed on your git branch, for example in a pull request; deletions are skippedfalse
--basethe branch --changed-only compares withorigin/HEAD, then main, then master
--unpublishedcompares with the current translations instead of the published onesfalse
--overridden-onlycompares 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 overridesfalse

Trying it safely

OptionWhat it doesDefault
--dryshows what would change in Locize, and changes nothing; it does not show what it would write into or delete from your filesfalse
--backup-deleted-pathsaves the keys that sync deletes in Locize into this foldernone

Plans: --unpublished and --overridden-only count 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:

bash
locize sync --path ./locales --auto-translate true

Send only the keys of the current branch, for a pull request:

bash
locize sync --path ./locales --changed-only true --auto-translate true

On 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:

bash
locize sync --path ./locales --reference-language-only false --review true

See what would change:

bash
locize sync --path ./locales --dry true