I want to change the language of a my application according to the default language of the device in which the app is installed. For example: if the default language of the device is French, the user will use the app in French.

I've tried to search for a solution, but probably I don't understand how to do that. Anyone can help me? Every help will be gretly appreciated.

有帮助吗?

解决方案

To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time.
Create the resource subdirectories and string resource files. For example:

MyProject/
    res/
       values/
           strings.xml
       values-es/
           strings.xml
       values-fr/
           strings.xml

Where fr = french

And in /values-fr/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="title">Mon Application</string>
    <string name="hello_world">Bonjour le monde !</string>
</resources>

Source = Multi language

其他提示

use qualifiers on your strings i believe fr is for france. So if you have a resource folder called values-fr, then anyone with french on their phone will get the french string file located in that folder and everyone else will get the string file in the values folder (without the -fr qualififer)

You can use qualifiers in all kind of resources of your app. You can for example, have a different layout depending on user language (it's useful on japanese or arabic language).

http://developer.android.com/guide/topics/resources/localization.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top