Saturday, July 28, 2012

Developing multi-language Android app

Developing your apps with User Interface in Android is easy, but your get to follow the guidelines.
  • Don't hard code text. Use Resource (strings.xml).
  • Avoid integrate text into picture (icon, banner, etc)
  • Use short wording
Let see some an example.
The default language of the apps "Baby milkfeed counter" is English. That mean whatever you device language setting is, the apps will display UI in the English.

Let's focus on the field "Fed Today".


 The below is a extract of the /res/layout/main.xml. 

		        android:text="@string/fedToday" />

The above text "@string/fedToday" was a tag stored in /res/values/strings.xml. Text field stored in this file are default language in this app (i.e. English). Let see the extract content of this string.xml.


    Last feed time
    Last volume
    Since last feed
    Fed today
    Fed Yesterday

Rather than hard code the text "Fed Today" in /res/layout/main.xml , I store it as string in /res/values/strings.xml. In fact, you should store all the text that will display in UI in the strings.xml. To implement multilingual UI, I don't need to change other file, but just add another file, /res/value-<locale>/strings.xml.

For example, to implement the app's UI in Traditional Chinese, I just need to prepare another strings.xml, as in /res/values-zh-rTW/strings.xml.



The process is completed. As you can see, the UI development did not involved any Java code, or even any file, just string.xml. To switch between go to the Android setting change the Language. launcher icon and UI textwill changed based on the device setting.

For every setting language, you get to prepare a separate /res/value-<locale>/strings.xml. if the device can find the its own language's string.xml, it uses the default one. Language and the strings.xml path mapping is as below.

Default /res/value/strings.xml
CANADA  /res/value-en-rCA/strings.xml
CANADA-FRENCH  /res/value-fr-rCA/strings.xml
CHINA  /res/value-zh-rCN/strings.xml
CHINESE  /res/value-zh/strings.xml
ENGLISH  /res/value-en/strings.xml
FRANCE  /res/value-fr-rFR/strings.xml
FRENCH  /res/value-fr/strings.xml
GERMAN  /res/value-de/strings.xml
GERMANY  /res/value-de-rDE/strings.xml
ITALIAN  /res/value-it/strings.xml
ITALY  /res/value-it-rIT/strings.xml
JAPAN  /res/value-ja-rJP/strings.xml
JAPANESE  /res/value-ja/strings.xml
KOREA  /res/value-ko-rKR/strings.xml
KOREAN  /res/value-ko/strings.xml
PRC  /res/value-zh-rCN/strings.xml
SIMPLIFIED-CHINESE  /res/value-zh-rCN/strings.xml
TAIWAN  /res/value-zh-rTW/strings.xml
TRADITIONAL-CHINESE  /res/value-zh-rTW/strings.xml
UK  /res/value-en-rGB/strings.xml
US  /res/value-en-rUS/strings.xml

For more locale info  for Android Development  / SDK, check with the following

Supporting Different Languages




  1. Gr8 Sharing Keep it up......thanks for sharing....

    Free Download ALl Smart Phones Applications, Games, Themes

  2. Hi there! If you are working on creating multilingual Android app, I recommend trying It has a simple UI and lots of useful features (API, translation memory, Gengo integration, automatic translation, WordPress plugin) that will simplify your workflow.