Get string from default locale using string in specific locale

Viewed 17614

Ok, I know title sound crazy :)

Here is what I want. My app is localized for device user but information I send back to server need to be all English. My default app locale English.

For example, I have array:

  • Apples
  • Oranges
  • Peaches

I have localized array:

  • Яблоки
  • Апельсины
  • Персики

When russian user sees list and selects couple items - I need to get corresponding english versions.

I guess my answer boils down to how to do getString() and pass locale? Or how do I get Array in specific locale?

8 Answers

If you use JB 2.2.x or above (basically API >= 17) you can use createConfigurationContext do:

public String translate(Locale locale, int resId) {  
    Configuration config = new Configuration(context.getResources().getConfiguration()); 
    config.setLocale(locale);   
    return context.createConfigurationContext(config).getText(resId);
}
Related