Pages

Monday, February 2, 2015

Android beginner tutorial Part 86 Localization

In this part we will talk about application localization.

After deployment, your application may be used on Android devices in many regions. To get the most users, you should think about making your application suitable for people speaking different languages - in other words, you should localize it.

Localization is actually fairly easy to implement. Up until now, when we set labels to buttons and text values to textviews and other components, we stored those values in strings.xml file (except some individual cases where we simply hard-coded the text in the xml files for testing purposes). Localization system lets us create multiple string, audio, visual, etc. files for different regions.

By using the res/values/strings.xml file, youre setting the default values for all regions. When told to look for a resource, the Android system picks the one that suits the region of the user. If no such item exists, the default value is picked. Thats why if youre using resources in your application, you should always include all of the used values that would be used by default.

The default values stored in res/values/ directory should be using the most common language you expect your application users to speak. Normally, its English.

To set resources for other regions, use the values-<qualifiers> pattern to create new directories and store your resources there. The <qualifiers> can be replaced by one or a group of qualifiers (for example, we know we can store images for different pixel density using qualifiers such as mdpi, hdpi, etc.).

As the Android official docs state: the language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r").

Examples of such language codes are "en", "fr", "ca", as well as "en-rUS", "fr-rFR" and "fr-rCA".

This means that we can store values in directories like res/values/strings.xml, res/values-fr/strings.xml, res/values-ja/strings.xml, etc.

And that is pretty much it. Using this information youll be able to make a flexible Android application which adapts to the users region.

Thanks for reading!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.