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.
| Format | Package | Languages in a file | Context | Notes for translators | "Needs review" mark | Inline markup | Updated in place |
|---|---|---|---|---|---|---|---|
| JSON | json | one | – | – | – | – | yes |
| PHP arrays | php-array | one | – | – | – | – | yes |
| YAML | yaml | one | – | – | – | – | – |
| gettext PO | po | source and one translation | msgctxt | #. comments | fuzzy | – | yes |
| XLIFF 1.2, 2.0 | xliff | source and one translation | – | <note> | target and segment state | <g>, <x/>, <ph>, <pc>… | yes |
| String Catalog | xcstrings | all | – | comment | needs_review | – | yes |
| Android resources | android | one | – | – | – | <b>, <a>, <xliff:g>… | yes |
| gettext MO | mo | one | msgctxt | – | – | – | – |
WordPress .l10n.php | l10n-php | one | msgctxt | – | – | – | – |
- 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 bygetFile().
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:
LaravelSyntaxfor Laravel's:nameandapple|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-formatflags, 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.