1

I need to know if it is possible to select a specific resource locale for my language.

Instead of changing my phone's language setting, can I in code make use of it depending upon some conditions?

Here's a piece of code I wrote: A user should be able to change language and see its effect inside the app itself.

String appLocale = LanguageManager.getCurrentUserSelectedLanguage();

if (appLocale.equals("en" /*or "de" or "es" etc */)) {
    ResourceBundle _resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);
    localizedString = _resources.getString(key);
} ...

return localizedString;
Nate
  • 31,017
  • 13
  • 83
  • 207
Atif Imran
  • 1,899
  • 2
  • 18
  • 33

1 Answers1

0

Finally I was able to solve the issue! This is for all who are interested. Here's the code:

if(appLocale.equals("en")){
ResourceBundle _resources = ResourceBundle.getBundle(LocalizationResource.BUNDLE_ID, LocalizationResource.BUNDLE_NAME).getBundle(Locale.get(Locale.LOCALE_en));
localizedString = _resources.getString(key);
}
else if(appLocale.equals("es")){
ResourceBundle _resources = ResourceBundle.getBundle(LocalizationResource.BUNDLE_ID, LocalizationResource.BUNDLE_NAME).getBundle(Locale.get(Locale.LOCALE_es));
localizedString = _resources.getString(key);
}

I used only one resource file(.rrh) and simply picked up the language bundle using Locale.LOCALE_es and Locale.LOCALE_en depending upon my app language I received from the user.

Atif Imran
  • 1,899
  • 2
  • 18
  • 33