Android
LingoHub supports Android .xml files, the standard resource format for localizing Android applications.
LingoHub also offers tight coupling between Apple iOS and Android projects to accelerate multi-mobile development. You can create one of these projects and export the translated resource files in the other format.
Format
- The format is based on XML.
- LingoHub supports the
string,string-array, andpluralselements. - Comments use standard XML syntax and are assigned to the following key/value pair.
- Placeholder syntax is documented in the Java Formatter reference.
LingoHints can be included in a comment:
<!-- <lh>{"status": "DRAFT","qc": {"min": "0","max": "20"},"labels": ["q3-2024"],"not_translatable": false}</lh> -->Example
Additional example files are available on GitHub.
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="deutscher string">actually german: muss grösser gleich %d sein</string>
<string name="escaped quotes">Logged in as \"%s\"</string>
<string name="escaped single quotes">Logged in as \'%s\'</string>
<string name="surrounded quotes">"Logged in as '%s'"</string>
<string name="surrounded quotes escaped">"Logged in as \'%s\'"</string>
<!-- single line comment -->
<string name="two placeholder newline">Hello %s!\nYou have got %s unread messages.</string>
<!-- multi
line -->
<!-- comment -->
<string name="with html content"><i>left</i></string>
<!-- string-array comment -->
<string-array name="planets_array">
<item>Mercury</item>
<!-- Venus comment -->
<item>Venus</item>
<item>Earth</item>
<!-- Mars comment -->
<item>Mars</item>
</string-array>
<string-array name="months">
<item>January</item>
<item>February</item>
<item>March</item>
<item>April</item>
<item>May</item>
<item>Jun</item>
<item>July</item>
<item>August</item>
<item>September</item>
<item>October</item>
<item>November</item>
<item>December</item>
</string-array>
<!-- strings quantity comment -->
<plurals name="numberOfSongsAvailable">
<!-- one comment -->
<item quantity="one">Znaleziono jedną piosenkę.</item>
<item quantity="few">Znaleziono %d piosenki.</item>
<!-- other comment -->
<item quantity="other">Znaleziono %d piosenek.</item>
</plurals>
</resources>To consider
XML-related export rules
Rule: The characters & and < must be escaped as & and < unless they are part of an escape sequence (e.g., ") or an element tag (e.g., <b>). Otherwise, the XML document is not well-formed.
Exception: If a string element contains HTML (e.g., <u>), the behavior depends on the HTML export setting:
- RAW: HTML tags are not escaped. Only the characters
&and<are escaped according to the rule above. - ESCAPE: All occurrences of
<,>, and&are escaped, including those in HTML tags. - CDATA: The content is wrapped in a
CDATAsection and no XML entity escaping is applied.
If the content is already wrapped in a CDATA section during import, LingoHub also exports it inside a CDATA section, regardless of the HTML export setting.
Android-related export rules
- If a single quote (
') appears in the content, it must be either escaped as\'or the entire string must be enclosed in double quotes ("). - The double quote character (
") must be escaped as\". - For quoted text such as
" this is some text ", no trimming is applied on import. The whitespace is preserved in the exported file. - If HTML tags (e.g.,
<b>,<i>,<u>) are present alongside format strings (e.g.,%1$d), all HTML tags are escaped as if the ESCAPE export setting were selected. - If format strings are used, any other occurrences of
%must be escaped using the corresponding Unicode code point representation. LingoHub always escapes the percent sign when it is not used as a format string (e.g.,"Save 50 only now!"). Exception: if the XML attributeformatted="false"is present on the element, no percent sign escaping is applied. - The characters
@and?are escaped with\if they appear at the beginning of the content (or represent the only content), unless the entire string is enclosed in double quotes (") or they represent references (e.g.,@string/keyName). - Newlines are escaped as
\n, tabs are escaped as\t, and the backslash character is escaped as\\.
Additional export rules
- The rules under "Android-related export rules" are always applied, even if the content is inside a
CDATAsection (whether imported that way or created by the corresponding HTML export option). - If the export option Escape Unicode Characters is selected, all non-ASCII characters are also replaced by the corresponding Unicode code point representation.
- If a non-Unicode encoding (e.g., ASCII) is selected, Unicode escaping is applied implicitly.
Locale information
In typical Android projects, resource files do not require locale information in the filename (a common name is strings.xml). The locale information is derived from the directory path. For this reason, using the LingoHub SCM integration to synchronize your repository is recommended. Otherwise, you must specify the language manually when importing the file.
References
Updated about 1 month ago
