There are two sets of string resources: default (English) and Russian. It is necessary to set the Russian language if the user chooses Belarusian, Ukrainian, etc. First, I find out what language the user has now:

String userLocale = Locale.getDefault().getLanguage(); 

Then compare with the right languages:

 if(userLocale.equals("uk")||userLocale.equals("be")||userLocale.equals("kz")) и т.д. 

Inside if'a code found here:

 Locale locale = new Locale("ru"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources(). updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); 

But when you start the application, the language does not change to Russian, but remains defaulted. What am I doing wrong?

  • upd: Select in system settings - Pacs31 4:08 pm
  • It is best to implement the choice of language regardless of the system - Flippy pm
  • Maybe so, but the main problem is that the code inside if'a does not work. Those. if you leave it alone, nothing changes. - Pacs31 4:16 pm

1 answer 1

You need to create a folder in the resources for the necessary languages ​​and place the necessary translation there. It is from these folders that the strings will be taken. Those. create the values-ua , values-be , values-kz strings.xml and put the strings.xml with the Russian translation there - everything will work out of the box, you will not need to do anything programmatically.

  • How then to make changes / additions? First do them in the Russian version, and then copy them to the rest? - Pacs31
  • @ Pacs31, yes, exactly. You change one file and then replace it in other folders - YuriySPb