Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library/api which converts language code to language name

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.

like image 500
Abhishek Jain Avatar asked Apr 20 '26 14:04

Abhishek Jain


2 Answers

The Java Locale class can do this:

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

You just have to parse the language/country names.

like image 75
mkhelif Avatar answered Apr 22 '26 15:04

mkhelif


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
like image 25
publysher Avatar answered Apr 22 '26 15:04

publysher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!