gpt4 book ai didi

Android Java show Western numerals when locale is set to Arabic instead of Eastern Arabic Numerals(当区域设置设置为阿拉伯语而不是东阿拉伯数字时,Android Java会显示西方数字)

转载 作者:bug小助手 更新时间:2023-10-24 18:29:05 26 4
gpt4 key购买 nike



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

更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com