3

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!

Adam
  • 43,763
  • 16
  • 104
  • 144
  • Given that those are essentially two separate _languages_, how do you expect a _locale_ to differentiate between both? – fge Jul 20 '15 at 18:12
  • @fge I don't know. But, locales do include a language component. Java uses it to translate month names and such. So, is there a way to differentiate? – Adam Jul 20 '15 at 18:16
  • Submitted a ticket to Unicode CLDR: http://unicode.org/cldr/trac/ticket/8792 – Adam May 18 '16 at 00:59

2 Answers2

2

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

Locale.forLanguageTag("zh-yue").getDisplayName() 
Philip O.
  • 288
  • 2
  • 8
1

This is actually Mandarin:

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

But, yes, you get Chinese

You can use:

Locale.SIMPLIFIED_CHINESE.getDisplayName(Locale.ENGLISH) 

for Chinese (China)

and

Locale.TRADITIONAL_CHINESE.getDisplayName(Locale.ENGLISH)

for Chinese (Taiwan)

and

Locale.forLanguageTag("zh-HK").getDisplayName(Locale.ENGLISH)

for Chinese (Hong Kong)

malix
  • 3,566
  • 1
  • 31
  • 41