编程语言
首页 > 编程语言> > java-如何从Android上的Locale对象获取脚本?

java-如何从Android上的Locale对象获取脚本?

作者:互联网

从我的角度来看,Android Locale class并未提及任何有关脚本的内容,仅提及语言,国家/地区和版本.

尽管Java SE Locale class提到了语言,国家/地区,脚本,变体和扩展名,但是当然还有一种获取脚本的方法getScript().

因此,我的问题是:如何从Android上的Locale对象获取脚本?

还是有另一种获取脚本的方法?

我需要它能够区分繁体中文(zh-Hant)和简体中文(zho-Hans),因为我需要能够从语言环境中获取脚本,例如赞特语或汉斯语

脚本=

ISO 15924 alpha-4 script code. You can find a full list of valid
script codes in the IANA Language Subtag Registry (search for “Type:
script”). The script field is case insensitive, but Locale always
canonicalizes to title case (the first letter is upper case and the
rest of the letters are lower case).
Well-formed script values have the form [a-zA-Z]{4}
Example: “Latn” (Latin), “Cyrl” (Cyrillic)

解决方法:

此功能未内置在Android SDK中.相反,我写了一个可以使用的版本,可用here.基本上,它将上面的答案中的表移植到Map< String,Map< String,String>>中.包含有用的信息,然后使用一种简单的查找方法.要在您的项目中使用此类,只需调用:

String script = LocaleUtilities.getScript(Locale.getDefault());

获取默认语言环境的脚本.

标签:chinese-locale,locale,java,android,localization
来源: https://codeday.me/bug/20191030/1967226.html