13

My application supports 4 languages. The user select their language. But this is not working for Russian.

if (dil.equals("eng")){
        Configuration c = new Configuration(context.getResources().getConfiguration());
        c.locale = Locale.ENGLISH;
        context.getResources().updateConfiguration(c,context.getResources().getDisplayMetrics());
        
    }
    else if (dil.equals("ger")){
        Configuration c = new Configuration(context.getResources().getConfiguration());
        c.locale = Locale.GERMAN;
        context.getResources().updateConfiguration(c,context.getResources().getDisplayMetrics());
        
    }
    else if (dil.equals("rus")){
        Configuration c = new Configuration(context.getResources().getConfiguration());
        c.locale = Locale.????????;
        context.getResources().updateConfiguration(c,context.getResources().getDisplayMetrics());
        
    }
    else
    {
        Configuration c = new Configuration(context.getResources().getConfiguration());
        c.locale = Locale.getDefault();
        context.getResources().updateConfiguration(c,context.getResources().getDisplayMetrics());
        
    }

I don't know what to do for Russian.

c.locale = Locale.????????;
Community
  • 1
  • 1
enginar
  • 307
  • 1
  • 6
  • 16

2 Answers2

41

Using this constructor you can set your locale to Russian like this:

Locale myLocale = new Locale("ru","RU");

Here is a list of supported locales by Java. You can see that "ru" is supported , but not tested.

The documentation also says some times its better to give base localization and internationalization so I edited from

Locale myLocale =  new Locale("ru") 

to

Locale myLocale = new Locale("ru","RU")
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
0

According to Android documentation for Locale

This class' constructors do no error checking. You can create a Locale for languages and countries that don't exist, and you can create instances for combinations that don't exist (such as "de_US" for "German as spoken in the US").

Note that locale data is not necessarily available for any of the locales pre-defined as constants in this class except for en_US, which is the only locale Java guarantees is always available.

It is also a mistake to assume that all devices have the same locales available. A device sold in the US will almost certainly support en_US and es_US, but not necessarily any locales with the same language but different countries (such as en_GB or es_ES), nor any locales for other languages (such as de_DE). The opposite may well be true for a device sold in Europe.

Furthermore the documentation does not list a Locale for Russian so looks like you have to create one. Also pay attention to third paragraph of the above quote. So perhaps it is better to provide your own.

Check this SO post as well it has some helpful tips for Locale

Community
  • 1
  • 1
Orlymee
  • 2,349
  • 1
  • 22
  • 24