The wizard generates an Android app that contains translated strings for multiple languages as shown below.
The language codes (ar, cs, da, de, en, es, etc.) can be looked up at Codes for the Representation of Names of Languages.
Strings used within the app are read from the appropriate version of the strings_localized
or strings.xml
file. The strings.xml
file contains strings that are provided at design time, such as the screen names from metadata.xml
or the app name. Android Studio provides a Translations Editor that you can use to view the values across the localized strings files. Right-click on the strings.xml
file and choose Open Translations Editor.
Notice in the screenshot below that the resources that are from the strings.xml
file, such as Suppliers, are not translated. These will get translated in Step 3.
The following code in the WelcomeActivity
class, in the onCreate
method, is an example of the code used to read from a strings file.
The getString
method determines what the current local language is on the device or emulator and then reads from the matching strings file.
You can set the language on an Android device or emulator using Settings > System > Languages & input > Languages. A second language, such as French, can also be added.
Select the default language by long pressing on a language and dragging it to the top of the list.
When the app is restarted, it now shows strings in the preferred language if that language is supported by the app. If the language is not currently supported, the strings will be in English by default.