Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 18  Localization


Localizing Resources


Language settings are part of the device’s configuration. (See the section called Device configurations
and alternative resources in Chapter 3 for an overview of device configuration.) Android provides
qualifiers for different languages, just as it does for screen orientation, screen size, and other
configuration factors. This makes localization straightforward: You create resource subdirectories with
the desired language configuration qualifier and put the alternative resources in them. The Android
resource system does the rest.


In your CriminalIntent project, create a new values resource file (as you did in Chapter 17): In the
project tool window, right-click res/values/ and select New → Values resource file. Enter strings
for the File name. Leave the Source set option set to main. Make sure Directory name is set to values.
Select Locale in the Available qualifiers list and click the >> button to move Locale to the Chosen
qualifiers section. Select es: Spanish in the Language list. Any Region will be automatically selected in
the Specific Region Only list – which is just what you want, so leave that selection be.


The resulting New Resource File window should look similar to Figure 18.2.


Figure 18.2  Adding a qualified strings resource file


Note that Android Studio automatically changes the Directory name field to values-es. The language
configuration qualifiers are taken from ISO 639-1 codes, and each consists of two characters. For
Spanish, the qualifier is -es.

Free download pdf