5

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:

  • 1,21,31..x1 книга
  • 2-4, 2(2-4), 3(2-4), .., x(2-4) книги
  • in other cases - книг

In english:

  • 1 book
  • n books

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?

3 Answers3

4

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.

gmazzo
  • 1,135
  • 13
  • 15
  • This does not change the way plurals work in the app, only changes behavior for lint. With English set on device it will still show wrong plurals. – V-master Apr 05 '22 at 11:54
0

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

Sachin
  • 1,307
  • 13
  • 23
0

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());
    }
asim
  • 310
  • 1
  • 8