How to write multilingual Android apps?

By | July 22, 2013

To build multilingual Android apps you need to collect the texts into resource files and translate them.

Once you provide the translation, Android OS will choose the resources that match user’s locale. If your application is available in several languages, Android will select the language that the device uses.

In this tutorial, we’ll cover:

  • Application localization process
  • Translating strings
  • Localizing images
  • Running and testing the localized application

In order to have a multilingual Android app you need to provide Android with the localized resource files.

If the locale is ‘en-US’, Android will look for a value of “R.string.title” by searching the files in the following order:

  • ‘res/values-en-rUS/strings.xml’
  • ‘res/values-en/strings.xml’
  • ‘res/values/strings.xml’

  • Translating Strings

    For example if an application requires four strings.xml files, one for each in English, Italian, French, and Russian.

    The procedure for creating strings.xml files is as follows:

    • Translate the strings.xml file to each language
    • Create three new folders under res – values-it, values-fr and values-ru (The original values folder already exists).
    • Place the translated strings.xml files in the respective folders.

    Localizing Images

    If our application also needs six more drawable folders, each containing a variant of the background image.

    Place background image that has to appear for a respective language in corresponding folders under the project workspace of the application as specified in below Table.

    If your images contain texts, we recommend creating copies of the texts in your strings.xml file. This way, translators can translate just the texts, and you can rebuild the localized images.

    Background image Destination folder in project workspace
    Italian drawable-it-rIT/background.png
    French drawable-fr-rFR/background.png
    French (Canada) drawable-fr-rCA/background.png
    English (Canada) drawable-en-rCA/background.png
    Russian drawable-ru-rRU/background.png
    US English drawable-en-rUS/background.png
    Default (Earth image) drawable/background.png

    Running and Testing the Localized Application

    Once the localized string and image resources are added to the project workspace, the application is ready for testing. To test it, we can set different locales via Home > Menu > Settings > Locale & text > Select locale.

    Depending on configuration of the device, some devices may offer only a few locales or may not offer any alternate locales via the settings application. However, the Android emulator will offer a selection of all the locales that are available in Android OS. To set the emulator to a locale that is not available in the system image, you can use Custom Locale, available in the Application tab.

    Hope you enjoyed this post, Please leave a comment at the end.

    Leave a Reply

    Your email address will not be published.