问题描述
塞尔维亚语具有拉丁字母和西里尔字母.在Android的日期和时间选择器"小部件中,显示的塞尔维亚语言环境字母似乎是西里尔字母,如此处所示.
The Serbian language has Latin and Cyrillic alphabets. In Android's Date and Time Picker widgets, the displayed alphabet for Serbian locales seems to be Cyrillic, as seen here.
我想更改语言环境,以便android小部件使用拉丁塞尔维亚字母.
I wanted to change the locale so that the android widgets are using the Latin Serbian alphabet.
当前的语言/国家/地区代码(生成西里尔字母)分别为sr
和RS
.因此,我的setLocale函数称为
The current language/country code (yielding Cyrillic) are sr
and RS
respectively. Therefore, my setLocale function is called as
setLocale("sr", "RS");
这是我不确定的部分-根据 localeplanet.com ,拉丁塞尔维亚语的本地代码为sr_Latn_RS
.但是,我都尝试过
setLocale("sr_Latn", "RS");
//and
setLocale("sr_Latn_RS", "RS");
两者均无效(不变,默认为英语).根据Android文档,setLocale看起来需要两个字母代码.
So how do I specify a Latin serbian locale code? Or does it not exist?
推荐答案
如果您仅支持Lollipop或更高版本,则以上答案非常有效.但是,如果您使用塞尔维亚语编码,则很多用户群可能都没有.这是适用于新旧版本的解决方案.
private static Locale serbianLatinLocale(){
Locale locale = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
for (Locale checkLocale : Locale.getAvailableLocales()) {
if (checkLocale.getISO3Language().equals("srp") && checkLocale.getCountry().equals("LATN") && checkLocale.getVariant().equals("")) {
locale = checkLocale;
}
}
} else {
locale = new Locale.Builder().setLanguage("sr").setRegion("RS").setScript("Latn").build();
}
return locale;
}
这篇关于如何更改语言环境以使用拉丁塞尔维亚语(而不是西里尔文塞尔维亚语)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!