Thursday, October 15, 2009

Android Internationalization

To provide internationalization of your applications on Android, all you have to do is create "values" folders for each language you wish to implement.

Eg: If your application supports English and Spanish, then you would have the default "values" folder for English, and "values-es" for spanish. You can then create a "strings.xml" for each folder and put your language specific strings in them. Be sure that your strings have the same "name" attribute across each folder. If the phone is configured in Spanish, and the user clicks on your application, Android will automatically read the "values-es" folder for strings.

Im not sure about this, but it is my guess that this can be extended for other folders as well. That way, you can have one logical code base, but can have multiple layouts, strings, colors etc.

What I am sure off, is that this functionality can also be extended for different devices that have different hardware and settings. You have just append the right qualifies to your "values" folder.

If you goto: File -> New -> Other -> Android -> Android XML File

After you choose your .xml filename, and you select the type of resource, you then have a list of qualifiers which you can choose, and for each qualifier you can enter the value in the textbox.

So for the above example, I would type "strings.xml" as the filename, Select "values" as the resource type, choose the "Language" qualifier, and for Spanish I will type "es" in the textbox and click "Finish". Android will then create my srings.xml file in /res/values-es.

For more information on Android resources and internationalization, check this out: http://developer.android.com/guide/topics/resources/resources-i18n.html

2 comments: