Supporting Different Languages

Android will run on many devices in many regions and therefore, the phone will be in different languages. To reach the most users, your application should handle text and graphics in ways appropriate to the locales where your application will be used.

To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code “es”. Android loads the appropriate resources according to the locale settings of the device at run time.

Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:

MyProject/
    res/
       values/
           strings.xml
       values-es/
           strings.xml

Add the string values for each locale into the appropriate file.

At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user’s device.

For example, the following are some different string resource files for different languages.

English (default locale), /values/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">Hello World!</string>
</resources>

Spanish, /values-es/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Mi Aplicación</string>
<string name="hello_world">¡Hola Mundo!</string>
</resources>

The same with images

MyProject/
    res/
       drawable/
           background.png
       drawable-es/
           background.xml

You can download this code: Download code