我正在使用
java.util.Locale生成一个区域设置列表并打印出它们的本地显示语言(即打印出ja_JP作为日本语).我注意到zh_CN(简体中文)和zh_TW(繁体中文)本地化为中文而不是简体中文和繁体中文.有没有办法让这些语言环境包含简化和传统的前缀字符而不用硬编码zh_CN应该是简体中文和zh_TW应该是繁体中文?我知道我可以打印语言国家(即中文),但这并不完全相同.
这是一个java片段,证明它们是相同的:
import java.util.Locale; public final class test { public static void main(String[] args) { Locale locale1 = new Locale("zh","cn"); System.out.println( locale1.getDisplayLanguage(locale1)); System.out.println( locale1.getDisplayLanguage(Locale.TRADITIONAL_CHINESE)); System.out.println( locale1.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE)); System.out.println( locale1.getDisplayCountry(locale1)); System.out.println( ""); Locale locale2 = new Locale("zh","tw"); System.out.println( locale2.getDisplayLanguage(locale2)); System.out.println( locale2.getDisplayLanguage(Locale.TRADITIONAL_CHINESE)); System.out.println( locale2.getDisplayLanguage(Locale.SIMPLIFIED_CHINESE)); System.out.println( locale2.getDisplayCountry(locale2)); } }
解决方法
以下列方式实例化Locale对象应解决您的问题:
Locale locale1 = new Locale("zh","CN"); Locale locale2 = new Locale("zh","TW");