Why does the display language for simplified Chinese relate to the ISO code?

import java.io.UnsupportedEncodingException; import java.util.Locale; public final class ForeignTextDemo { public static void main(String[] args) throws UnsupportedEncodingException { Locale locale = new Locale("TW"); System.out.println(locale.getDisplayLanguage(Locale.TRADITIONAL_CHINESE)); locale = new Locale("CN"); System.out.println(locale.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE)); } } 

When I run the program above, I get the following output:

 ε₯‘ηΆ­ζ–‡cn 

But, if I change the second language to locale = new Locale("ZH"); , I will get the desired result:

 ε₯‘ηΆ­ζ–‡δΈ­ζ–‡ 

Why is this? I really want the simplified Chinese language display language . Is this β€œZH” exactly that?

+4
source share
2 answers

Just "cn" is not a local, full local "zh_CN", to distinguish between "tw_CN".

See the list of supported locales .

 locale1 = new Locale("zh", "cn") println locale1.getDisplayLanguage(locale1) println locale1.getDisplayLanguage(Locale.TRADITIONAL_CHINESE) println locale1.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE) println locale1.getDisplayLanguage(Locale.TAIWAN) println locale1.getDisplayCountry(locale2) println locale1.country println "" locale2 = new Locale("tw", "cn") println locale1.getDisplayLanguage(locale2) println locale2.getDisplayLanguage(Locale.TRADITIONAL_CHINESE) println locale2.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE) println locale2.getDisplayLanguage(Locale.TAIWAN) println locale2.getDisplayCountry(locale2) println locale2.country 
+4
source

According to the Javadoc for java.util.Locale , the single-arg constructor for Locale() expects an ISO 639-1 language code . The ISO 639-1 language code for Chinese is "ZH".

What you actually provide with your "TW" and "CN" strings is ISO 3166-1 . Country codes for Taiwan and China.

+1
source

Source: https://habr.com/ru/post/1380397/


All Articles