Localize the Application Localize the Strings

The application requires three more strings.xml files, one each for German, French, and Japanese. In this example, we will start by copying res/values/strings.xml into newres/values-<qualifier>/strings.xml files.

Under the res / directory, create the three new directories and copy res/values/strings.xml into each of them. For example, using Eclipse you could do it like this:

1. Right-click the res/values/ folder and select Copy.

2. Right-click on the res / folder and select Paste. Rename the folder values-de and click OK

>i strings.xmi O AndroidManifest.xml

>i strings.xmi O AndroidManifest.xml

^ Name Conflict

Q

Enter a new name for 'values':

values-de|

OK

Cancel

3. Repeat steps 1 and 2 two more times, for values-fr, and values-ja. Now the project includes these new files, all still containing British English text strings:

res/values-de/strings.xml res/values-fr/strings.xml res/values-ja/strings.xml

4. Replace the strings in the three new files with localized text. To do this, open the res/values-<qualifier>/strings.xml files and replace the code as follows:

File

Replace the contents with the following code:

res/values-de/strings.xml

<?xml version=n1.0M encoding="utf-8,,?> <resources>

<string name="app name">Hallo, Lokalisierung</string> <string name="text a">Soll ich dich einem Sommertag vergleichen,</string>

<string name="text b">Der du viel lieblicher und sanfter bist?</string> </resources>

res/values-fr/strings.xml

<?xml version="1.0" encoding="utf-8"?> <resources>

<string name="app name">Bonjour, Localisation</string> <string name="text a">Irai-je te comparer au jour d'été?</string> <string name="text b">Tu es plus tendre et bien plus tempéré.</string> </resources>

res/values-ja/strings.xml

<?xml version="1.0" encoding="utf-8"?> <resources> <string

<string name="text </string> </resources>

Tip: In the values-<qualifier>/strings.xml files, you only need to include text for strings that are different from the default strings. For example, when the application runs on a device that is configured for Japanese, the plan is for text a and text b to be in Japanese while all the other text is in English, so res/values-ja/strings.xml only needs to include text aand text b.

Localize the Images

As shown in Table 2, the application needs six more drawable folders, each containing a flag.png icon. Add the needed icons and folders to your project:

1. Save this German flag icon as res/drawable-de-rDE/flag.png in the application's project workspace.

1. Click the link to open the flag image.

2. Save the image in your-wor£:space/HelloL10N/res/drawable-de-rDE/ .

2. Save this French flag icon as res/drawable-fr-rFR/flag.png in the application's project workspace.

3. Save this Canadian flag icon as res/drawable-fr-rCA/flag.png in the project workspace.

4. Save the Canadian flag icon again, this time as res/drawable-en-rCA/flag.png in the project workspace. (Why not have just one folder that contains the Canadian flag? Because a folder qualifer cannot specify a region without a language. You cannot have a folder named drawable-rCA/; instead you must create two separate folders, one for each of the Canadian languages represented in the application.)

5. Save this Japanese flag icon as res/drawable-ja-rJP/flag.png in the project workspace.

6. Save this United States flag icon as res/drawable-en-rUS/flag.png in the project workspace.

If you are using Eclipse, refresh the project (F5). The new res/drawable-<qualifier>/ folders should appear in the project view.

0 0

Post a comment