在這個例子中,將獲得默認的語言環境並列印其詳細資訊。 然後為“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)顯示語言