Android: How to get string in specific locale WITHOUT changing the current locale

前端 未结 5 2013

Use Case: Logging error messages as displayed to the user.

However you don\'t want to have messages in your log that depend on the locale of the user\'s device. On t

5条回答
  •  没有蜡笔的小新
    2020-12-05 06:52

    Try this:

      Configuration conf = getResources().getConfiguration();
      conf.locale = new Locale("ar"); // locale I used here is Arabic
    
      Resources resources = new Resources(getAssets(), getResources().getDisplayMetrics(), conf);
      /* get localized string */
      String appName = resources.getString(R.string.app_name);
    

提交回复
热议问题