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-22 18:18:22 27 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 "١٢٣٤٥".

在Android中,如果用户选择阿拉伯语作为他们的语言,我想将区域设置为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

Java语言


NumberFormat nf = NumberFormat.getInstance(new Locale("ar","EG")); //Egipt uses western arabic numbers
nf.format(your_string);

更多回答

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