Localization for Russian on Android

my application suppresses 4 languages. user selects his language. But I canโ€™t do for the Russians.

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 do not know the dong for the Russian language;

 c.locale = Locale.????????; 
+6
source share
2 answers

Using this constructor , you can set your language to Russian as follows:

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

The following is a list of supported Java locales . You can see that "ru" is supported but not checked.

The documentation also says several times to better give basic localization and internationalization, so I edited from

 Locale myLocale = new Locale("ru") 

to

 Locale myLocale = new Locale("ru","RU") 
+17
source

According to Android Documentation for Locale

The constructors of this class do not check for errors. You can create a locale for languages โ€‹โ€‹and countries that do not exist, and you can create instances for combinations that do not exist (for example, "de_US" for "German, as they say in the USA").

Note that locale data is not necessarily available for any of the locales previously defined as constants in this class, with the exception of en_US, which is the only guarantee Java Java is always available.

It is also a mistake to assume that all devices have the same locales. 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 in different countries (for example, en_GB or es_ES), as well as any locales for other languages โ€‹โ€‹(for example, de_DE ) For a device sold in Europe, the reverse may well be the case.

In addition, the documentation does not indicate the language for the Russian language, so you must create it. Also pay attention to the third paragraph of the above quote. Therefore, it may be better to provide your own.

Check out this SO post as well as some helpful tips for Locale

0
source

Source: https://habr.com/ru/post/917518/


All Articles