Home » Android » Localization for Russian in Android

Localization for Russian in Android

Posted by: admin May 14, 2020 Leave a comment

Questions:

my application supprts 4 language. user select him/her language. But i cant do taht 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 dont know dong for Russian;

c.locale = Locale.????????;
How to&Answers:

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")

Answer:

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