Android string resources provide text data for your application with optional styling and formatting. There can be three types of string resources: string, string-array, plurals.  Here is an example of how Android resource file should look:

<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>

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.

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",  it will only be exported for the base language. The following custom attributes are available for Android keys:

{
    "translatable": "false",
    "force-cdata": true
}

You can read more about custom key attributes for other formats in the Custom attributes section. 

Exporting resources

When exporting Android string resources from Lokalise, our exporter automatically performs the following tasks:

  • automatic text wrapping in CDATA if HTML tags are present with the exception of <a>, <b>, <i>, <u>, <font> and <xliff> tags
  • automatic conversion of line breaks to \n
  • automatic escaping of single/double quotes and other symbols
  • automatic setting of the formatted="false" attribute if there is more than one non-positional placeholder present
Did this answer your question?