Search code examples
androidlocale

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


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.


Solution

  • 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