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, you're 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. That's why if you're 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, it's English.
To set resources for other regions, use the values-
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 you'll be able to make a flexible Android application which adapts to the user's region.
Thanks for reading!
http://kirill-poletaev.blogspot.it/2013/02/android-beginner-tutorial-part-86.html
Please login in order to leave a comment.