如何更改语言环境以使用拉丁塞尔维亚语(而不是西里尔文塞尔维亚语) [英] How to change locale to use Latin Serbian (instead of Cyrillic Serbian)

查看:281
本文介绍了如何更改语言环境以使用拉丁塞尔维亚语(而不是西里尔文塞尔维亚语)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

塞尔维亚语具有拉丁字母和西里尔字母.在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.

当前的语言/国家/地区代码(生成西里尔字母)分别为srRS.因此,我的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.但是,我都尝试过

This is the part im not sure about - according to localeplanet.com, the local code for latin serbian is sr_Latn_RS. However, I tried both

setLocale("sr_Latn", "RS");
//and
setLocale("sr_Latn_RS", "RS");

两者均无效(不变,默认为英语).根据Android文档,setLocale看起来需要两个字母代码.

neither of which work (no change occurs, default to english). According to the Android documentation, it looks like setLocale expects two letter codes.

语言代码是两个字母的小写ISO语言代码(例如 如"en"),如ISO 639-1所定义.国家/地区代码为两个字母 ISO 3166-1定义的大写ISO国家/地区代码(例如"US"). 变体代码未指定.

The language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1. The country codes are two-letter uppercase ISO country codes (such as "US") as defined by ISO 3166-1. The variant codes are unspecified.

那么,如何指定拉丁语的塞尔维亚语言环境代码?还是不存在?

So how do I specify a Latin serbian locale code? Or does it not exist?

推荐答案

如果您仅支持Lollipop或更高版本,则以上答案非常有效.但是,如果您使用塞尔维亚语编码,则很多用户群可能都没有.这是适用于新旧版本的解决方案.

The previous answer works well if you only support Lollipop or above. However, if you're coding in Serbian a lot of your user base probably won't have it. Here's a solution that works for old and new versions.

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

这篇关于如何更改语言环境以使用拉丁塞尔维亚语(而不是西里尔文塞尔维亚语)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆