Managing strings for localization

Move all strings into strings.xml

As you build your apps, don't hard code any string. Instead, declare all of your strings as resources in a default strings.xml file, which makes it easy to update and localize. Strings in the strings.xml file can then be easily extracted, translated, and integrated back into your app (with appropriate qualifiers) without any changes to the compiled code.

If you generate images with text, put those strings in strings.xml as well, and regenerate the images after translation.

Follow Android guidelines for UI strings

As you design and develop your UIs, make sure that you pay close attention to how you talk to your user. In general, use a succinct and compressed style that is friendly but brief, and use a consistent style throughout your UIs.

Make sure that you read and follow the Material Design recommendations for writing style and word choice. Doing so makes your apps appear more polished to the user and helps users understand your UI more quickly.

Also, always use Android standard terminology wherever possible—such as for UI elements such as Action Bar, Options Menu, System Bar, Notifications, and so on. Using Android terms correctly and consistently makes translation easier and results in a better end-product for users.

Provide sufficient context for declared strings

As you declare strings in your strings.xml file, make sure to describe the context in which the string is used. This information is invaluable to the translator and result in better quality translation. It also helps you manage your strings more effectively.

Here is an example:

Consider providing context information that may include:

·         What is this string for? When and where is it presented to the user?

·         Where is this in the layout? For example, translations are less flexible in buttons than in text boxes.

Mark message parts that should not be translated

Often strings contain text that should not be translated into other languages. Common examples might be a piece of code, a placeholder for a value, a special symbol, or a name. As you prepare your strings for translation, look for and mark text that should remain as-is, without translation, so that the translator doesn't change it.

To mark text that should not be translated, use an <xliff:g> placeholder tag. Here is an example tag that ensures the text "%1$s" isn't changed during translation (otherwise it could break the message):

When you declare a placeholder tag, always add an id attribute that explains what the placeholder is for. If your apps later replace the placeholder value, be sure to provide an example attribute to clarify the expected use.

Here are some more examples of placeholder tags: