Plan the Localization

The first step in localizing an application is to plan how the application will render differently in different locales. In this application, the default locale will be the United Kingdom. We will add some locale-specific information for Germany, France, Canada, Japan, and the United States. Table 1 shows the plan for how the application will appear in different locales.

Region / Language

United Kingdom

Germany

France

Canada

Japan

United States

Other Location

English

British English text; British flag (default)

British English text; Canadian flag

-

British English text; U.S. flag

British English text; British flag (default)

German

German text forapp_name, t ext_a andtext_ b; German flag

German text forapp_name, t ext_a andtext_ b; British flag

French

French text forapp_name, t ext_a andtext_ b; French flag

French text forapp_name, t ext_a andtext_ b; Canadian flag

French text forapp_name, t ext_a andtext_ b; British flag

Japanese

Japanese text fortext_a andte xt_b; Japanese flag

Japanese text fortext_a and t ext_b; British flag

Other Language

-

-

-

-

-

-

British English text; British flag (default)

Note that other behaviors are possible; for example, the application could support Canadian English or U.S. English text. But given the small amount of text involved, adding more versions of English would not make this application more useful.

As shown in the table above, the plan calls for five flag icons in addition to the British flag that is already in the res/drawable/ folder. It also calls for three sets of text strings other than the text that is in res/values/strings.xml.

Table 2 shows where the needed text strings and flag icons will go, and specifies which ones will be loaded for which locales. (For more about the locale codes, see Alternate Resources.)

Table 2

Locale Code

Language / Country

Location of strings.xml

Location of flag.png

Default

English / United Kingdom

res/values/

res/drawable/

de-rDE

German / Germany

res/values-de/

res/drawable-de-rDE/

fr-rFR

French / France

res/values-fr/

res/d rawa ble-fr-rF R/

fr-rCA

French / Canada

res/values-fr/

res/drawa ble-fr-rCA/

en-rCA

English / Canada

(res/values/)

res/drawable-en-rCA/

ja-rJP

Japanese /Japan

res/values-ja/

res/drawable-ja-rJP/

en-rUS

English / United States

(res/values/)

res/drawable-en-rUS/

Tip: A folder qualifer cannot specify a region without a language. Having a folder named res/drawable-rCA/, for example, will prevent the application from compiling.

At run time, the application will select a set of resources to load based on the locale that is set in the user's device. In cases where no locale-specific resources are available, the application will fall back on the defaults.

For example, assume that the device's language is set to German and its location to Switzerland. Because this application does not have a res/drawable-de-rCH/ directory with a flag.pngfile in it, the system will fall back on the default, which is the UK flag located in res/drawable/flag.png. The language used will be German. Showing a British flag to German speakers in Switzerland is not ideal, but for now we will just leave the behavior as it is. There are several ways you could improve this application's behavior if you wanted to:

• Use a generic default icon. In this application, it might be something that represents Shakespeare.

• Create a res/drawable-de/ folder that includes an icon that the application will use whenever the language is set to German but the location is not Germany.

0 0

Post a comment