Android Translate a string

Download Android for free


Strings can be internationalised by defining a different strings.xml for each language you support.

You add a new language by creating a new values directory with the ISO language code as a suffix. For example, when adding a German set your structure might look like follows:

enter image description here

When the system looks for the requested string it first checks the language-specific xml, if it is not found, the value from the default strings.xml file is returned. The key remains the same for each language and only the value changes.

Example contents:


<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">HelloWorld</string>
    <string name="hello_world">Hello World!</string>


<?xml version="1.0" encoding="utf-8"?>
    <string name="hello_world">Bonjour tout le monde !!!</string>
Working with strings.xml file