Get string from default locale using string in specific locale

后端 未结 8 989
温柔的废话
温柔的废话 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:47

    I believe, this is the safe way to go (without touching current configuration):

    Configuration conf = new Configuration();
    conf.setToDefaults();   // That will set conf.locale to null (current locale)
    // We don't want current locale, so modify it
    conf.locale = new Locale("");   // Or conf.locale = Locale.ROOT for API 9+
                                    // or conf.setLocale(Locale.ROOT) for API 14+
    // Since we need only strings, we can safely set metrics to null
    Resources rsrcDflt = new Resources(getAssets(), null, conf);
    String apples = srcDflt.getString(R.string.apples); // Got it at last!
    

提交回复
热议问题