为什么简体中文的显示语言要采用ISO代码?
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));
}
}
当我运行上面的程序时,我得到以下输出:
契維文
cn
但是,如果我将第二个语言环境更改为 locale = new Locale("ZH");
,我会得到所需的输出:
契維文
中文
为什么这是这样? 我真正想要的是简体中文的显示语言。 “ZH”就是这个吗?
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 locale to locale = new Locale("ZH");
, I get the desired output of:
契維文
中文
Why is this? What I really want is the display language for Simplified Chinese. Is "ZH" just that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是“cn”不是语言环境,完整的本地语言是“zh_CN”以区别于“tw_CN”。
请参阅支持的区域设置列表。
Just "cn" isn't the locale, the full local is "zh_CN" to differentiate with "tw_CN".
See the list of supported locales.
根据
java.util.Locale
的 Javadoc,Locale()
的单参数构造函数需要一个 ISO 639-1 语言代码。中文的 ISO 639-1 语言代码是“ZH”。您实际提供的“TW”和“CN”字符串是 ISO 3166-1< /a> 台湾和中国的国家/地区代码。
According to the Javadoc for
java.util.Locale
, the single-arg constructor forLocale()
expects an ISO 639-1 language code. The ISO 639-1 language code for Chinese is "ZH".What you are actually providing with both your "TW" and "CN" strings are the ISO 3166-1 Country Codes for Taiwan and China.