Android XML

XML String Resource files to use with Android mobile app localization.

File Extensions .xml
API Extension xml
Format Options convert_placeholder, escape_linebreaks, enclose_in_cdata
Import Yes
Export Yes
Pluralization supported? Yes
Descriptions/Comments supported? Yes


<?xml version="1.0" encoding="UTF-8"?>
  <!-- this is a comment -
    headline of my software project -->
  <string name="app_title">My Software Project</string>
  <string name="greeting">Hello \'User\'!
How are you doing today?</string>
  <string-array name="my_collection">
  <plurals name="new_messages">
    <item quantity="one">You have a new message</item>
    <item quantity="other">You have %{count} new messages</item>
    <item quantity="zero">You have no new messages</item>

Format Options

Option Type Upload Download Default Description
convert_placeholder boolean close check false Placeholder will be converted to match format specific requirements. Example: '$@' => '$s'
escape_linebreaks boolean close check false All linebreaks will be escaped as '\n'.
enclose_in_cdata boolean close check false Encloses translations containing html tags in CDATA

“My HTML tags are not displayed when setting the text via view.setText”

Use this to set the text of the view.

SpannedString text = new SpannedString(getResources().getText(R.string.my_text));

“I can not use placeholders in formatted text”

To format text containing placeholders like “Hello <b>%1$s</b>”, you have two options.

  • Escape the HTML in PhraseApp
  • Escape the HTML in your code.

To do it in the code, set the text of the view like this:

SpannedString rawText = new SpannedString(getResources().getText(R.string.my_text));
String formattedString = String.format(Html.toHtml(rawText), "Jack");
SpannedString formattedText = new SpannedString(Html.fromHtml(formattedString));

Which would result in the output “Hello Jack!”

“Using a colorcode (#ff0000) in my font tag causes the text not to show”

Escape the HTML in the string or use a method similar to the one above.

SpannedString rawText = new SpannedString(getResources().getText(R.string.my_text));
SpannedString text = new SpannedString(Html.fromHtml(Html.toHtml(rawText)));

“How do I escape my HTML in PhraseApp and use it?”

  1. Escape the HTML in PhraseApp (replace < with &lt; and > with &gt;)
Hello &lt;b&gt;World&lt;/b&gt;!
  1. Use the translation center or the API Client to download your translations.

  2. Set the text in Java like so

String rawString = getResources().getString(R.string.my_text);
SpannedString text = new SpannedString(Html.fromHtml(rawString));
  1. The output should be “Hello World!”

“Why is the ‘translatable=false’ tag ignored in PhraseApp?”

The translatable=false attribute on the <string> element is not evaluated and persisted in PhraseApp. However if a string should not be translated, you can define all your non-translatable strings in a seperate resource file, for example donottranslate.xml. Since these strings should never be translated, there is no need to push this file to PhraseApp. More information can be found here.

“Can I share my translations between iOS and Android?”

If you want to share your translations between iOS and Android there are several things you should have in mind:

  1. Use simple key names with no special characters and without white spaces - use underscores or dots instead. Most of the special characters are not supported in Android resource files. Rather than using the generated key names from Xcode like RMx-3f-FxP.title, use descriptive key names like ‘myniceapp.title’. This also makes them more readable.
  2. Avoid using CDATA tags because they are difficult to handle in iOS and can be avoided by correctly escaping the strings in most cases.
  3. Activate the “Escape line breaks” format option when exporting for Android to get an identical output on both platforms.

Further Reading