Search code examples
androidlocalizationlocale

Android: choosing between two languages without "locale"


I'm developing application that can be useful only in my country(Ukraine). In Ukraine people primary speak Ukrainian or Russian. And I need to create something like radioButton to switch between languages.

Until now I only found tutorials that were using "locale", but it will not suit my needs, because location is same (Ukraine) but languages are different.

So let's imagine that I have saved in database parameter that show language

I created 2 types of res/values (values-ua & values-rus). I am starting activity what code I need to use to show which resources I need?


Solution

  • I think your problem is that you used the wrong country codes. Try values-ru and values-uk. [source]

    Not fully sure what you intend to do, but I would not provide any radio button. Instead, I would rely on android's built in support for localization. In other words, suppose user A has a device with the Ukranian language enabled by the os, the app will automatically use the strings provided in the strings.xml file which resides in the values-uk folder. Same goes for russian. Check this answer- it might help.