区域设置详细信息(Locale Details)

优质
小牛编辑
124浏览
2023-12-01

在此示例中,我们将获取默认语言环境并打印其详细信息。 然后为“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());  
   }
}

输出 (Output)

它将打印以下结果。

Default Locale Properties:
United States
English
English (United States)
USA
eng
en
US
fr Locale Properties:
France
French
French (France)
FRA
fra
fr
FR