Iced Tea Labs Share to be shared

Support Multiple Languages in Android

A - Introduction

In Android development, you can keep the UI strings seperately with app code by storing all the strings in external files.

You can find the res folder in Android project structure. Within this res directory are subdirectories for various resource types.

There’re some default xml files in res folder such as res/values/strings.xml which contails all application’s strings.

To support multiple languages in Android, simply, we have to provide different string.xml files for each language.

B - Create Locale Directories and String Files

To support multiple languages in Android, firstly you have to create different res/values folders for each language. The res/values folder must include the ISO country code at the end of the its name. For example: res/values-fr will contains all values for French apps.

Inside each res/values folder, you must define the string.xml file with appropriate supported language.

multiple languages

The content of string.xml files:

<?xml version="1.0" encoding="utf-8"?> 

    <string name="app_name">DemoMultipleLanguages</string> 
    <string name="hello_world">Hello world!</string> 
    <string name="action_settings">Settings</string> 

<?xml version="1.0" encoding="utf-8"?> 

    <string name="app_name">Demostración Múltiples idiomas</string> 
    <string name="hello_world">¡Hola, mundo </string> 

<?xml version="1.0" encoding="utf-8"?> 

    <string name="app_name">Demo plusieurs langues</string> 
    <string name="hello_world">Bonjour tout le monde </string> 


P/S: I used Google Translate for Spanish and French so please don’t mind if there’re any rediculous mistakes about translations.

C - Use String Resources

It’s super easy to get the String resource value:

// Get a string resource from your app's Resources 
String hello = getResources().getString(R.string.hello_world); 

// Or supply a string resource to a method that requires a string
TextView textView = new TextView(this);
<RelativeLayout xmlns:android="" 
    tools:context="ice.tea09.demomultiplelanguages.MainActivity$PlaceholderFragment" > 

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


And the result for this demo:




D - Download Source Code Support Multiple Languages in Android

comments powered by Disqus