Change the language of the app according to the default language of the device

StackOverflow https://stackoverflow.com/questions/22451231

  •  15-06-2023
  •  | 
  •  

Frage

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.

War es hilfreich?

Lösung

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

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top