Android. How change default locale fo string.xml in values

I have an application with only russian locale. If I am not mistaken, the string.xml in the res/values is the english locale by default. But english and russian have different plurals. For example:

In russian:

In english:

Problems begin when the user changes system language from russian to other language. How can I change default language for my application? Or maybe it is possible to force the application to use the russian plurals?

Upvotes: 6

Views: 4613

Answers (3)

gmazzo
gmazzo

Reputation: 1265

I finally found the answer: https://developer.android.com/studio/write/tool-attributes#toolslocale

<resources xmlns:tools="http://schemas.android.com/tools"
tools:locale="es">

From the doc:

This tells the tools what the default language/locale is for the resources in the given element (because the tools otherwise assume English) in order to avoid warnings from the spell checker. The value must be a valid locale qualifier.

Upvotes: 4

asim
asim

Reputation: 310

create new value folder values-ru and place string.xml in that.

in java change your app language programatically with this code. for change to rushion call method with ru parameter like this changeLanguage("ru").

public void changeLanguage(String languageToLoad) {
        //for language change
        Locale locale = new Locale(languageToLoad);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    }

Upvotes: 0

Sachin
Sachin

Reputation: 1448

you can create different String.xml files

like this

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

Check google official document https://developer.android.com/training/basics/supporting-devices/languages.html & https://developer.android.com/guide/topics/resources/localization.html

Upvotes: 0

Related Questions