Get string from default locale using string in specific locale

The code below will retrieve localized string for polish language even if the default locale on the device is different:

Configuration conf = getResources().getConfiguration();
conf.locale = new Locale("pl");
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources resources = new Resources(getAssets(), metrics, conf);
/* get localized string */
String str = resources.getString(R.string.hello);

I hope this also apply to other resource types like array, so it should suffice to replace "pl" with "en"...


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);
}