java如何从Android上的Locale对象获取脚本?
据我所见Android Locale class没有提到任何关于脚本的内容,只有语言、国家和变体
而Java SE Locale class提到了语言、国家、脚本、变体和扩展,当然还有一个方法getScript()来获取脚本
因此,我的问题是:如何从Android上的Locale对象获取脚本强>
或者有没有其他方法来获取脚本
我需要这个能够区分中国繁体(zho Hant)和中国简体(zho Hans),因为我需要能够从现场获取脚本,例如,zho语言的Hant或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)
# 1 楼答案
此功能未内置在Android SDK中。相反,我编写了一个可以使用的版本,可用here。基本上,它将上面答案中的表移植到包含有用信息的
Map<String, Map<String, String>>
,然后使用简单的查找方法。要在项目中使用此类,只需调用:获取默认语言环境的脚本