我无法获得基于区域的本地化字符串。
我的电话号码基于用户所在的地区或国家/地区。
我有5个不同的地区和3种不同的语言。语言文件夹是值-es,values-en,values-ru。 5个区域是值-en-rAU,值-en-rUS,值-es-rCL,值-es-rUY。
在我的默认值/ strings.xml中,我有:
<string name="help_phone_number">(888)888—8888</string>
在其他人中,我有不同的数字,如
<string name="help_phone_number">(888)888—1111</string>
但它始终显示默认字符串值。我在模拟器中运行我的应用程序并以这种方式更改区域设置,但也尝试在代码中手动更改它,因为我认为它不能使用:
@NonNull
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static String getStringByLocal(Activity context, int id, String locale) {
Configuration configuration = new Configuration(context.getResources().getConfiguration());
configuration.setLocale(new Locale(locale));
return context.createConfigurationContext(configuration).getResources().getString(id);
}
当我打印出语言环境时,它是正确的。但字符串仍然显示默认字符串。