Search code examples
androidresourceslocaletranslationiso

Multi languages resources with proper language code


I want to make application, that will support languages with resources depending of actual localization and country code. According to Documentation I need to change resources to format i.e. values-en-rUS, and in that configuration app sucessful compile and proper flag image in resources is set it up but I dont know what format should be write in Locale variable to change resources. I try en_US , en-rUS , en-US but does doesnt work correctly. In my previous version with resources like values-en changing Locale of the app language to en the resources are updating correctly.


Solution

  • Locale for values-en-rUS can be obtained by new Locale("en", "US"), this will get instance of "en_US" locale (matching values-en-rUS).

    Don't use new Locale("en_US") this will produce "en_us". That doesn't match values-en-rUS. Also new Locale("en-US") will not work.

    From API level 21, there's handy Locale.forLanguageTag(String) method. It returns a locale for the specified IETF BCP 47 language tag string, which is "en-US" in this case. So you can use Locale.forLanguageTag("en-US).