Java library/api which converts language code to l

2019-07-10 08:27发布

Is there a Java library/api which , given an iso language code, returns the corresponding language name. For example zh-cn should return chinese, en should return english and so on.

3条回答
放荡不羁爱自由
2楼-- · 2019-07-10 09:13

The Java Locale class can do this:

new Locale("zh", "cn").getDisplayName();
--> Chinese (China)

You just have to parse the language/country names.

查看更多
Deceive 欺骗
3楼-- · 2019-07-10 09:29

Locale API does the country code for java languages.Refer the above link

查看更多
手持菜刀,她持情操
4楼-- · 2019-07-10 09:33

You don't need a library; you can use java.util.Locale for this.

Locale locale = new Locale("zh", "cn");
System.out.println(locale.getDisplayLanguage());

This will print

Chinese
查看更多
登录 后发表回答