Android string resources files (.xml) provide text data for your application with optional styling and formatting. There can be three types of string resources: string
, string-array
, and plurals
.
Technical information
Overview
Format name:
Android Resources
File extensions:
.xml
Common use cases:
Managing localized text strings in Android applications, including optional styling and formatting.
Technical details:
Structure: Android resource files are XML files containing various types of string resources: simple strings, string arrays, and plurals.
Encoding: UTF-8
Example:
Here's an example of a typical Android resource file:
<resources>
<string name="simple_string">Hello world!</string>
<string name="string_with_placeholders">Hello %s!</string>
<string name="string_w" formatted="false">%s jobs in %s days</string>
<string name="string_with_html_formatting">Hello <b>world</b>!</string>
<string name="string_with_other_html"><![CDATA[<h1>Hello world!</h1>]]></string>
<plurals name="plural_string">
<item quantity="one">%s cat</item>
<item quantity="other">%s cats</item>
</plurals>
<string-array name="array_of_strings">
<item>Always</item>
<item>When possible</item>
<item>Never</item>
</string-array>
</resources>
In this example, the welcome
key has a single translation, while the nested
array demonstrates how to organize translations hierarchically.
Known limitations
Key naming limitations
All keys must be named according to the following regexp: ^[a-zA-Z_$]+[a-z0-9_$A-Z]*
.
Keys must start with a Latin character, underscore, or a $ symbol.
Keys can contain Latin characters, underscores, $ symbols, and numbers.
Using improper naming might cause unexpected results upon exporting (certain key names might be trimmed or even replaced with an empty string).
String arrays
All keys with square brackets and indexes are converted to string-arrays. In the example above, the keys are array_of_strings[0]
, array_of_strings[1]
, and array_of_strings[2]
.
Plurals
Plurals are created by defining a key as plural in the Lokalise editor. Android supports the following plural forms: zero, one, two, few, many, other.
Using with Lokalise
Lokalise supports Android resource files, making it easy to manage your translations directly within the Lokalise platform. You can upload your Android resource files to Lokalise, edit the translations, and download the updated files back into your project.
Supported project types
Please note that XML files can be uploaded only to Web and mobile projects.
Key descriptions
You can add key descriptions to the uploaded XML translation files as follows:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<!-- Key description for "key1" goes here!-->
<string name="key1">This is the base language\'s text for key1.</string>
</resources>
To preserve key descriptions upon downloading, make sure to tick the Include description option under the Advanced settings section.
Custom key attributes
You can read more about custom key attributes for other formats in the Custom attributes article.
If you want to mark a key as translatable="false"
or force it to be exported as CDATA, you can do so via custom attributes in the Lokalise editor.
The following custom attributes are available for Android keys:
{
"translatable": "false",
"force-cdata": true
}
How such keys will be exported depends on the Empty translations setting under the Advanced tab on the Download page. Here are all possible scenarios:
Replace with base value — if you choose this option, all untranslatable keys will be included in the target language exports and their content will be the same as in the base language.
Export as empty strings — untranslatable keys will not be exported for the target languages and no XML elements will be created for them. Empty strings will still be exported as empty strings and empty XML elements will be created in all languages.
Do not export — untranslatable keys will not be exported in the target languages and the same will happen to the empty strings. In the base language, empty keys will be skipped as well.
Exporting resources
When you export Android string resources from Lokalise, the system automatically handles several tasks:
Text with HTML tags (like
<a>
,<b>
,<i>
,<u>
,<font>
, and<xliff>
) is wrapped in CDATA, except when placeholders are involved. For instance, in phrases likeWelcome, <b>%s</b>
or%s, <b>welcome</b>
, the text will be wrapped in CDATA due to the placeholders.Line breaks are automatically converted to
\n
.Special characters (like
#
,&
,/
,'
,"
, etc.) are escaped automatically. Note that periods (.
) and underscores (_
) are exceptions, and dashes (-
) are converted to underscores (_
). In rare cases, wrapping quotes may be incorrectly unescaped. If this happens, you can fix it by manually adding slashes in the editor.If more than one non-positional placeholder is present, the attribute
formatted="false"
will be set automatically.Region-specific language codes in directory names will have the
r
prefix added to follow Android standards. For example,values/en-US/strings.xml
becomesvalues/en-rUS/strings.xml
, as ther
before the region code is required by Android's official documentation.