Get string from default locale using string in specific locale

后端 未结 8 990
温柔的废话
温柔的废话 2020-12-06 09:58

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

8条回答
  •  长情又很酷
    2020-12-06 10:40

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

提交回复
热议问题