Saturday, June 19, 2010

Localisation & Internationalisation on Android, the easy way

You often hear about Internationalisation (internationalization in US English, or i18n for short), and Localisation (Localization in US English, or L10n for short) in software development circles... ever wonder what that's all about?

Of course you do.

Definitions vary, but the basic idea is generally easily summarised:
  • Internationalisation is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes.
  • Localisation is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text.

These two terms usually go hand-in-hand as the term 'globalisation'. See?
.. Course you do.

Each language is given a language code such as 'en-au' for Australian English, or 'en-us' for American English. These language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1.
But how do we use this? And how can we easily apply these concepts to our Android programming?

.. Good question!

Best practices in Android suggests defining all your string resources in a 'strings.xml' file (you're doing this already, right?) and placing that file in the 'res\values' folder in your project.

Localisation in Android is as simple as creating a new version of this file and folder, renaming the 'values' folder to 'values' + the language code you wish to support.

For example, all your Italian translations would be located in 'res\values-it\strings.xml', your Chinese translations in 'res\values-zh\strings.xml' as seen here:

If you don't happen to have a friend from whatever country you're trying to translate your app for, just use Google translate.

Once you're done your app is one simple step away from global domination.

All you need to do is copy those freshly translate strings back into a strings.xml file in Eclipse, and, as long as the folder the strings.xml file is located in has the name of 'values' + the language code you're wishing to support, magically any user who has their phone locale set to a locale that uses that language, your translated strings will be used.

No code changes are required.

Handy eh?


  1. You wrote "i10n", but it should be "i18n".

  2. Hi Nicolas,
    .. You're absolutely right, thanks for that, I've now corrected it.

  3. Thanks for this article. I always wanted to improve my application through translation. Now I believe your guidance will help me.

    > If you don't happen to have a friend from whatever country you're trying to translate your app for, just use Google translate.

    Recently I've found great tool crowdin. Thay may be better way to get your app localized. In case if any one interested:

  4. Thanks Dies, excellent suggestion, I'll check it out.

  5. Glenn, Very helpful quick guide to internationalization of an app - thanks! Do you know if it is easy to get the current locale. I have extensive documentation stored as HTML (displayed with a WebView widget) so I'd want to point to the correct HTML file at runtime.

  6. Stop! Protest! Please, please, please: DO NEVER EVER translate your apps using Google Translate or another such automated translation! The results are horrible! Much better have only an english version than an unusable ugly german or other version which the user cannot change. Please! :)

    1. Haha.. Yeh, I understand your point Bachi, but I disagree that it's much better to have just an English version.
      I have had users of my apps offer to help correct the translations in my apps, and therefore improve them, and I give those users credit in my apps, which helps build a bit of community.
      Exposure to non-english speaking markets is also very important.
      Would you stop using a great app just because the translations aren't correct? I wouldn't.
      Sure, it may not appear as professional as proper translations, but the exposure to new users I believe is worth it, especially as it is those users who can help improve your app.
      In any respect, the main point of this article wasn't 'use Google translate'.

      Have a good day,
      Glenn :)

  7. Replies
    1. Hi Maweceq,
      I don't think you can really localize a database, but you can get the users language settings via code and then choose different database fields containing different translations based on that language.