Search code examples
javalocalizationtranslationlocalechinese-locale

Is there a separate Java locale for Mandarin and Cantonese?


I'm trying to use the JDK to get the names of different languages translated into other languages. For example:

new Locale("en", "US").getDisplayLanguage(new Locale("en", "US")); // English
new Locale("en", "US").getDisplayLanguage(new Locale("fr", "FR")); // anglais

I'd like to do this to get "Mandarin" and "Cantonese", but

new Locale("zh", "CN").getDisplayLanguage(new Locale("en", "US")); // Chinese

Is there a locale variant I can use to get "Mandarin" and "Cantonese" instead of "Chinese"? Is there another Java library I can use to get the names of languages translated into other languages?

Thanks!


Solution

  • The following code returns "yue" in Java 8 but "Cantonese" in Java 14.

    Locale.forLanguageTag("zh-yue").getDisplayName()