File formats and presets

Updated

The CLI, the GitHub App and the CI integrations read and write twelve file formats, so an iOS, Android, Flutter, gettext or .NET project syncs the way a JSON project does. You pick the format once in translatize.config.json; everything else stays the same.

The twelve formats

Use the id in the first column as format. A single-language format has one file per language, so files needs the {lang} placeholder. A multi-language format can hold every language in one file.

IdExtensionLanguages per fileWhat is special
json.jsonMulti-languageTranslatize JSON: the language is the top-level key, then the dotted key and its value. Also written that way in a per-language file.
csv.csvMulti-languageA key column, one column per language and a status column. A value starting with =, +, - or @ is stored with a leading apostrophe so a spreadsheet does not run it as a formula, and the apostrophe is removed on the way back.
yaml.ymlMulti-languageOne top-level block per language, in the style Rails uses.
xliff.xlfSingle-languageXLIFF 1.2. Each unit pairs the source text with the translation, and a translation that is still missing stays as an empty entry.
po.poSingle-languagegettext. A missing translation stays as an empty entry for the translator.
arb.arbSingle-languageFlutter. A dot in a key is written as an underscore (app.title becomes app_title), because the Flutter tools turn keys into code names. A key's description is written as its @key entry.
resx.resxSingle-language.NET resources.
ios.stringsSingle-languageiOS .strings: "key" = "value";. Older UTF-16 files are read; files are written as UTF-8. Plurals belong in stringsdict or xcstrings.
android.xmlSingle-languageAndroid strings.xml. A dot in a key is written as an underscore, as in ARB. <string> and <plurals> entries come through.
xcstrings.xcstringsMulti-languageXcode String Catalog. Plurals are stored as plural variations, and the file always carries the source language.
stringsdict.stringsdictSingle-languageThe property list Apple apps use for plural rules, built from the ICU plurals in your values.
properties.propertiesSingle-languageJava properties. Read as UTF-8, with \uXXXX escapes understood; written as UTF-8, or as pure ASCII with escapes when you set escapeUnicode.

For plain JSON files with one language each, the CLI also has json-nested and json-flat. Those two are bare objects without the language key; see the CLI page. Everywhere a format id is accepted, they are too.

Plurals

In Translatize a plural is an ICU message, for example {count, plural, one {# item} other {# items}}.

  • xcstrings and stringsdict write it as Apple's plural rules and read the rules back as ICU.
  • Spacing and the order of the categories are normalized on the round trip, and =0 and =1 become zero and one.
  • What Apple's rules cannot express – select, ordinals, offsets, exact numbers such as =5 – is exported as plain text, so the app shows the raw message.
  • Device and width variations in a catalog are reduced to one text and the import reports a warning.
  • Placeholders are returned exactly as stored. Translatize does not convert %@, %1$s or {name} between platforms.
  • Android <plurals> are read and written as ICU plurals, with %d for #. Android holds one plural per key, so a value with text around the plural, or two plurals, stays a plain string, and the parser says so.
  • An exact case such as =0 goes into the zero slot, and comes back as =0 in a language that has no zero form of its own, such as English. Apple apps show it for 0; Android ignores it there and uses other.
  • When a file can't hold everything a value does (Android, String Catalogs, .stringsdict), an unchanged string in it never overwrites the stored value: a push of a file you didn't edit changes nothing.
  • Android text is read the way Android builds it: quotes are removed, and runs of spaces outside quotes count as one. Spaces that matter are written so they survive.
  • The other formats carry the ICU message as text.

Dots and underscores in Android and ARB

Android and ARB names cannot hold a dot, so checkout.pay is written checkout_pay, and every underscore reads back as a dot. A key that already exists on the branch keeps its exact spelling: first_name stays first_name. A brand new key from such a file is created with dots, so first_name becomes first.name. Name new keys in Translatize first if you want an underscore to stay one.

Java .properties and escaping

Java 8 and older load .properties files as Latin-1, so accented text needs \uXXXX escapes. Set "escapeUnicode": true next to "format": "properties" and pull writes pure ASCII. Without it the file is UTF-8. Both forms are read, escapes included. A file that is not UTF-8 is read as Latin-1 and the import reports a warning.

A pull that changes nothing leaves a file's bytes alone, so switching escapeUnicode on does not convert files you already have. Delete them and run pull to convert them now.

Config keys

These are the keys of translatize.config.json that decide where the files are and how they are read. The CLI page lists the others (apiUrl, projectId, namespace, branch).

KeyWhat it does
formatOne of the twelve ids above, or json-nested / json-flat.
filesPath pattern with {lang}, for example locales/{lang}.json. A multi-language format (json, csv, yaml, xcstrings) may use one path without it; then one file holds every language. With {lang} even those four write one file per language.
sourceFileThe source language's own file, for platforms that keep it apart – Android's values/strings.xml, a .NET project's Resources.resx. One fixed path without {lang}. Every other language follows files.
localeMapProject language code to the code your paths use, for example { "zh-TW": "zh-rTW" }. Each value is one path segment, and two languages cannot share one. In a one-file layout it applies on the way in only, so a pull that rewrites such a file uses the project's codes and warns you.
escapeUnicodetrue writes .properties as pure ASCII. Any other format with this key is a configuration error, even with false.
Paths stay inside the repository
Every path must stay inside the repository. In a monorepo a config can reach ../../packages/i18n/{lang}.json, but a path that leaves the repository, goes through a symbolic link out of it or points into .git is refused. Without a repository, files must stay in the config file's directory.

Project languages are bare codes such as de, plus zh-TW. A region in a file's own language tag is dropped (de_DE reads as de); the file still counts for the language its path names.

Presets

A preset writes the format and paths for a platform. Run one in the folder that will hold the config:

terminal
npx translatize init --preset android
npx translatize init --preset ios-strings
npx translatize init --preset xcstrings
npx translatize init --preset flutter
npx translatize init --preset gettext
npx translatize init --preset resx
PresetformatfilessourceFile
androidandroidapp/src/main/res/values-{lang}/strings.xmlapp/src/main/res/values/strings.xml
ios-stringsios{lang}.lproj/Localizable.strings–
xcstringsxcstringsLocalizable.xcstrings–
flutterarblib/l10n/app_{lang}.arb–
gettextpolocale/{lang}/LC_MESSAGES/messages.po–
resxresxResources.{lang}.resxResources.resx

--files replaces a preset's pattern and drops its sourceFile, which belonged to that pattern. There is no preset for stringsdict, properties, csv, yaml, xliff or json; give init the format and path instead, for example npx translatize init --format properties --files "messages_{lang}.properties".

What pull does with untranslated keys

A key with no translation in a language is left out of that language's file, so your app falls back to its default language instead of showing a blank. That holds for ios, android, arb, resx, one-language json and yaml, and always for properties and stringsdict.

Three kinds of file keep the key: xliff and po, where the empty entry is the translator's to-do item; csv and xcstrings; and any file that holds every language.

pull makes a file match the branch. A local key with no value on the branch for that language goes from the file, and shows in the removed count and in --dry-run. That changes your file, never the branch, and push never deletes a key. A pull that changes nothing leaves your files untouched, whatever their comments or order; a file that did change is rewritten from the export, so comments in it go.

A file can hold what its format can't carry here, such as an Android <string-array>, typed .resx data or a gettext plural entry. pull leaves such a file alone and names it. A translation file makes it exit 1, so stale translations show in CI. The source-language file only warns and exits 0, as a translatable="false" string is normal there. --force rewrites it anyway, and what it held is gone.

status --fail-on-missing still counts a left-out key as missing.

One example per preset

The config each preset writes, with the usual extras. All of them work with every recipe on the CLI, GitHub Action, GitLab CI and CI templates pages; only the path a push job watches follows the preset.

android

The source language lives in values/, so sourceFile names it. localeMap gives zh-TW its Android spelling, so it lands in values-zh-rTW/.

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "android",
  "files": "app/src/main/res/values-{lang}/strings.xml",
  "sourceFile": "app/src/main/res/values/strings.xml",
  "localeMap": { "zh-TW": "zh-rTW" }
}
app/src/main/res/values-de/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_title">Meine App</string>
    <string name="checkout_pay">Jetzt bezahlen</string>
</resources>

ios-strings

One .lproj folder per language, next to the config or spelled out in the pattern.

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "ios",
  "files": "{lang}.lproj/Localizable.strings"
}

xcstrings

One catalog holds every language, so files has no placeholder.

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "xcstrings",
  "files": "Localizable.xcstrings"
}

flutter

Pull before flutter gen-l10n so the build sees the latest translations. If your files use an underscore for a region, map it with localeMap.

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "arb",
  "files": "lib/l10n/app_{lang}.arb",
  "localeMap": { "zh-TW": "zh_TW" }
}

gettext

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "po",
  "files": "locale/{lang}/LC_MESSAGES/messages.po"
}

resx

The default language is Resources.resx, without a suffix.

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "resx",
  "files": "Resources.{lang}.resx",
  "sourceFile": "Resources.resx"
}

Formats without a preset

Java .properties, with the source language in the bundle's base file and ASCII output for older Java:

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "properties",
  "files": "src/main/resources/messages_{lang}.properties",
  "sourceFile": "src/main/resources/messages.properties",
  "escapeUnicode": true
}

Apple plural rules, one file per language:

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "stringsdict",
  "files": "{lang}.lproj/Localizable.stringsdict"
}

One CSV file for every language:

translatize.config.json
{
  "projectId": "your-project-id",
  "format": "csv",
  "files": "i18n/translations.csv"
}

How files are read

json-nested and json-flat are read and written by the CLI itself. For every other format, push and status send your file to the API to be read. The API only reads it and stores nothing; the request counts towards the token's rate limit. See the parse route.