gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:19 24 4
gpt4 key购买 nike

据我所见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)

最佳答案

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

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

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

关于java - 如何从 Android 上的 Locale 对象获取脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19153384/

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