我需要在 Java 中将 fr_FR
、en_GB
、ja_JP
(表示法语、英语和日语)等字符串转换为 ISO 639 -2 种表示形式:fre/fra
、eng、jpn
。
您知道表示法 fr_FR
是否符合某个标准吗?我还没有找到这方面的任何东西。
您知道如何将此表示法转换为 ISO 639-2(3 个字母)语言代码吗?
多谢!
更新:我知道 getISO3Language() 方法。我还知道,我可以通过迭代可用的语言环境来构建像 fr_FR
这样的字符串,然后使用 ISO 639-2 3 字母代码进行映射 - 因此,每当我搜索 3-我可以在我构建的地图中找到字母代码。问题是,直接解决方案更适合我。抱歉我没有从一开始就解释这一点。
I need to convert in Java from strings like fr_FR
, en_GB
, ja_JP
(meaning the French, English, and Japanese language) to their ISO 639-2 representations: fre/fra
, eng
, jpn
.
Do you know if the notation style fr_FR
complies to a certain standard? I haven't found anything in this regard.
Do you know how can I make the conversion from this notation to ISO 639-2 (3-letter) language codes?
Thanks a lot!
Update: I know the method getISO3Language(). And I also know that I could construct, by iterating the available locales, strings like fr_FR
and then make a mapping with the ISO 639-2 3-letter code - thus, whenever I search for a 3-letter code I can find in the map I constructed. The thing is that I would fit me much better a direct solution. Sorry that I didn't explained this from the beginning.
发布评论
评论(4)
您可以在 {language}_{country} /ResourceBundle.html#getBundle%28java.lang.String,%20java.util.Locale,%20java.lang.ClassLoader%29" rel="noreferrer">java.util.ResourceBundle.getBundle(String, Locale, ClassLoader)< /a>,所以使用符号风格不会那么糟糕。另一方面,还应该注意语言标签具有
{语言}-{国家/地区}
样式(不是下划线'_'而是连字符'-')。详细说明可以在 java.util 的 javadoc 中找到。区域设置。将
{language}_{country}
转换为 ISO 639-2(3 个字母)代码的简单方法是new Locale(str.substring(0,2)).getISO3Language()
,但似乎您正在寻找另一种方式,如下所示:上面的示例可以使用 nv-i18n 国际化包运行。如果您使用 Maven,请尝试将以下依赖项添加到您的 pom.xml 中,
或从 Maven 中央存储库直接。
nv-i18n 源代码和 javadoc 托管在 GitHub 上。
来源:https://github.com/TakahikoKawasaki/nv-i18n
Javadoc: http://takahikokawasaki.github.com/nv-i18n/
You can see the notation style
{language}_{country}
in the javadoc of java.util.ResourceBundle.getBundle(String, Locale, ClassLoader), so it won't be so bad to use the notation style. On the other hand, it also should be noted that language tags have{language}-{country}
style (not underscore '_' but hyphen '-'). Detailed description can be found in the javadoc of java.util.Locale.A simple way to convert
{language}_{country}
to ISO 639-2 (3-letter) code isnew Locale(str.substring(0,2)).getISO3Language()
, but it seems you are looking for another way like the following:The example above can be run with nv-i18n internationalization package. If you are using Maven, try to add the dependency below to your pom.xml,
or download nv-i18n's jar from Maven Central Repository directly.
nv-i18n source code and javadoc are hosted on GitHub.
Source: https://github.com/TakahikoKawasaki/nv-i18n
Javadoc: http://takahikokawasaki.github.com/nv-i18n/
评论太长了,所以...
前两个字母是语言代码:
最后两个字母是国家代码:
现在您已经在这方面找到了一些东西,可以解释该表示法对应的标准。
This too long for a comment so...
The first two letters are the language code:
The last two letters are the country code:
So now you have found something in this regard, that explains to which standards this notation corresponds.
创建一个 Locale 对象,然后使用 getISO3Language()。
http://download.oracle.com /javase/1.5.0/docs/api/java/util/Locale.html#getISO3Language()
Create a Locale object then use
getISO3Language()
.http://download.oracle.com/javase/1.5.0/docs/api/java/util/Locale.html#getISO3Language()
java.util.Locale 的文档中对此进行了全部讨论。两个字母的代码也来自 ISO 标准,并且 Locale 有一个方法 getISO3Language() 可以完成您想要的操作。
This is all discussed in the documentation of java.util.Locale. The two-letter codes are also from the ISO standards, and Locale has a method getISO3Language() that does what you want.