Djkgotso
Djkgotso

Reputation: 130

How can i make my application to display in different languages using android

I have an application that is running but i want to be able to change it to different languages like spanish and italian.please help me

Upvotes: 3

Views: 1519

Answers (3)

Jeje Doudou
Jeje Doudou

Reputation: 1706

In your project, add a "values-es" directory in the "res" directory. Then put a new file "string.xml" in this directory.You should now have a "string.xml" file in the "values" directory and a "string.xml" file in the "values-es" directory.

Now, you just have to put in EACH file something like that:

In the "string.xml" of the "values" directory:

<resources>
    <string name="toto">The value in the default language</string>
</resources>

In the "string.xml" of the "values-es" directory:

<resources>
    <string name="toto">The value in spanish</string>
</resources>

Now, in your code, when you'll call the "toto" string, it will choose the one in the right language.

Upvotes: 2

Jeje Doudou
Jeje Doudou

Reputation: 1706

You can provide a string.xml in "values-it" and "values-es" directories. The device will automatically use the resources corresponding to the device's language. One thing you have to know about it, is that the "values" directory will be used by default. So here's the behaviour if I have a "values" and a "values-es" directories: hen you'll launch your app, the device will check if its language is "es". If it's the case, it will use the "values-es" resources. In ALL the other cases, it will use the "values" directory.

Upvotes: 1

Vladimir
Vladimir

Reputation: 3822

You should read Localization article to learn more about it

Upvotes: 4

Related Questions