In Android, if the user chooses Arabic for their language, I want to set the locale to AR but keep all the numbers in the system as "12345". Currently they show as "١٢٣٤٥".
在安卓系统中,如果用户选择阿拉伯语作为他们的语言,我希望将地区设置为AR,但保留系统中的所有数字为“12345”。目前,它们显示为“١٢٣٤٥”。
Below is my function to change the locale:
以下是我更改区域设置的函数:
public void setLocale(String lang)
{
Locale myLocale;
if (lang.equals("ar"))
{
myLocale = new Locale(lang, "SA");
}
else
{
myLocale = new Locale("en");
}
Locale.setDefault(myLocale);
Resources res = getResources();
Configuration config = new Configuration(res.getConfiguration());
config.setLocale(myLocale);
config.setLayoutDirection(myLocale);
Context context = getActivity();
context = context.createConfigurationContext(config);
// Save the chosen language in SharedPreferences
SharedPreferences preferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("language", lang);
editor.apply();
Intent refresh = new Intent(context, getActivity().getClass());
refresh.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(refresh);
}
更多回答
优秀答案推荐
You may have to change the string number formats by hand.
您可能需要手动更改字符串数字格式。
Java
爪哇
NumberFormat nf = NumberFormat.getInstance(new Locale("ar","EG")); //Egipt uses western arabic numbers
nf.format(your_string);
更多回答
我是一名优秀的程序员,十分优秀!