Android string resources provide text data for your application with optional styling and formatting. There can be three types of string resources:
plurals. Here is an example of how Android resource file should look:
<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>
<item quantity="one">%s cat</item>
<item quantity="other">%s cats</item>
Key naming limitations
All keys must be named according to the following regexp:
In other words:
Keys must start with a Latin character, underscore, or a
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).
All keys with square brackets and indexes are converted to string-arrays. In the example above the keys are
Plurals are created by defining a key as plural in the Lokalise editor. Android supports the following plural forms:
Custom key attributes
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. Keep in mind, that if a key is marked as
translatable="false". The following custom attributes are available for Android keys:
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 be 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.
You can read more about custom key attributes for other formats in the Custom attributes section.
When exporting Android string resources from Lokalise, our exporter automatically performs the following tasks:
Automatic text wrapping in
CDATAif HTML tags are present with the exception of
However, please note that the above exceptions is not applied in cases when you have any tag with placeholders. For example:
%s, <b>welcome</b>. In these cases the text will be wrapped in
Automatic conversion of line breaks to
Automatic escaping of single/double quotes and other symbols. Please note that all special characters (
"etc) will be escaped. The only exceptions are
-will be converted to
_automatically. In rare cases Lokalise might incorrectly unescape wrapping quotes, when they should have been escaped. To solve this, you can manually add slashes in the corresponding positions using the editor.
Automatic setting of the
formatted="false"attribute if there is more than one non-positional placeholder present.