Skip to content

Choosing a format ​

Use the format your project already has: the translator works with ICU inside, and every formatter turns its file into ICU messages and back. What differs is what a file can carry besides texts.

FormatPackageLanguages in a fileContextNotes for translators"Needs review" markInline markupUpdated in place
JSONjsonone––––yes
PHP arraysphp-arrayone––––yes
YAMLyamlone–––––
gettext POposource and one translationmsgctxt#. commentsfuzzy–yes
XLIFF 1.2, 2.0xliffsource and one translation–<note>target and segment state<g>, <x/>, <ph>, <pc>…yes
String Catalogxcstringsall–commentneeds_review–yes
Android resourcesandroidone–––<b>, <a>, <xliff:g>…yes
gettext MOmoonemsgctxt––––
WordPress .l10n.phpl10n-phponemsgctxt––––
  • Context tells apart the same text with different meanings ("Open" of a menu and of a status): they are translated separately.
  • Notes go to providers of whole messages (language models) with the text, and back into the file.
  • The mark says a text was made by a machine and waits for a person; clearing it in an editor approves the text. See Machine translations and review.
  • Inline markup is kept: providers see only the words, and a translation with other tags is not taken.
  • Updated in place: updateFile() writes the texts into the file as it is — comments, order, states and what the translator does not store stay. A format without it is written anew by getFile().

Compiled files: MO and .l10n.php ​

What an application loads, not what a person edits: a PO file without its comments and flags (a .l10n.php file even without its plural texts). Keep the PO file as the one that is edited, and write these from it — with sync they are derived files, written anew after their PO file and never read back. Machine translations go into them by default, so the application shows them before they are reviewed.

Message syntax ​

Messages are ICU in every format. A file whose strings use another syntax is read through a MessageSyntaxInterface:

  • LaravelSyntax for Laravel's :name and apple|apples, with JSON and PHP arrays;
  • TextSyntax (core) for plain text, where { is just a character;
  • PO reads printf strings by their c-format/php-format flags, String Catalogs and native Android resources read their printf formats themselves.

Android: native or ICU ​

AndroidXmlFormatter writes resources the app reads with getString() and getQuantityString(): printf arguments and <plurals>. Native resources have no select, so a message with one is refused there. AndroidIcuXmlFormatter writes ICU strings that the app formats with android.icu.text.MessageFormat (API 24+) — with select and everything else.