Java国际化(i18n) Locale类详细示例

在这个例子中,将获得默认的语言环境并打印其详细信息。 然后为“fr”创建一个语言环境并打印其详细信息。

文件:I18NTester.java -

import java.util.Locale;

public class I18NTester {
   public static void main(String[] args) {
      Locale locale =Locale.getDefault();  

      System.out.println("Default Locale Properties:\n");

      System.out.println(locale.getDisplayCountry());  
      System.out.println(locale.getDisplayLanguage());  
      System.out.println(locale.getDisplayName());  
      System.out.println(locale.getISO3Country());  
      System.out.println(locale.getISO3Language());  
      System.out.println(locale.getLanguage());  
      System.out.println(locale.getCountry());  

      Locale frenchLocale = new Locale("fr","fr");

      System.out.println("\nfr Locale Properties:\n");
      System.out.println(frenchLocale.getDisplayCountry());  
      System.out.println(frenchLocale.getDisplayLanguage());  
      System.out.println(frenchLocale.getDisplayName());  
      System.out.println(frenchLocale.getISO3Country());  
      System.out.println(frenchLocale.getISO3Language());  
      System.out.println(frenchLocale.getLanguage());  
      System.out.println(frenchLocale.getCountry());  
   }
}

执行上面示例代码,得到以下结果 -

Default Locale Properties:

中国
中文
中文 (中国)
CHN
zho
zh
CN

fr Locale Properties:

法国
法文
法文 (法国)
FRA
fra
fr
FR

上一篇:Java国际化(i18n) Locale类

下一篇:Java国际化(i18n)显示语言

关注微信小程序
程序员编程王-随时随地学编程

扫描二维码
程序员编程王

扫一扫关注最新编程教程