Android XML
Android string resources (res/values/strings.xml): string and plurals elements, with Android's escaping.
| Format | Identifier | Extension |
|---|---|---|
| Android XML | android_xml | .xml |
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">Acme</string>
<string name="greeting">Bonjour, %1$s !</string>
<string name="share_hint">Appuyez sur \"Partager\" pour envoyer l\'invitation</string>
<plurals name="items">
<item quantity="one">%d article</item>
<item quantity="other">%d articles</item>
</plurals>
</resources>Keys
The root element must be <resources>. Each <string> and <plurals> child is a key named by its name attribute.
- A missing
name, or the same name twice, is an import error. - Other elements, such as
<string-array>,<integer>or<color>, are skipped with a warning. translatable="false"(in any letter case) marks a string Android never translates, such as an app name or a URL. transglot does not create a key for it, translate it, or count its words.
Plurals
<plurals> becomes a plural key, one form per <item quantity="...">. Each quantity must be a category the locale uses: Android lint often suggests zero or two for English, but English has only one and other, so such an item is an import error. A category the file leaves out is stored empty.
On export, a plural key is written as <plurals> with an <item> for every category of the locale, in order.
Escaping
Import decodes Android's string escapes: \', \", \\, \n, \t, \@, \? and \uXXXX (including surrogate pairs). An unknown escape loses its backslash. XML entities (&, <) decode as usual.
Export applies the reverse, in this order: backslashes are doubled; newlines, ' and " are escaped; &, < and > become entities; a value starting with @ or ? gets a leading backslash so Android does not read it as a resource reference.
Markup inside strings
A string is read as its text content. Inline elements inside a <string>, such as <b>, <i> or <xliff:g>, are not kept: only the text between them is imported. On export, <, > and & in a translation are written as entities, so markup in a translation reaches Android as text. Split a string that needs inline styling into separate keys.
Placeholders
Format arguments such as %1$s, %d and %.2f are kept exactly as written. See Placeholders.
What the file must be
- UTF-8. Other encodings, and files containing NUL bytes, are rejected.
- No
DOCTYPE. Android resource files never have one, and a file that does is rejected. - Comments are skipped on import and are not written on export.
Export
The file starts with an XML declaration and a <resources> root, four-space indentation, one <string> or <plurals> per key in byte order of the key names. An API pull names the file strings-{locale}.xml in its Content-Disposition header.