国际化:Java平台下的Locale类

Locale类有如下几个构造器:

1
2
3
4
5
Locale(String language)

Locale(String language, String country)

Locale(String language, String country, String variant)

通过构造方法实例化Locale对象:

1
2
3
4
5
6
7
8
9
10
11
12
public class LocaleTest {
public static void main(String[] args) {

//创建一个通用英语的locale.
Locale locale11 = new Locale("en");
//创建一个加拿大英语的locale.
Locale locale12 = new Locale("en", "CA");
//创建一个美式英语的locale,硅谷的英语
Locale locale13 = new Locale("en", "US", "SiliconValley");

}
}

Locale类有一些预定义的Locale对象实例:

Locale Name Locale
Locale.CHINA zh_CN
Locale.CHINESE zh
Locale.SIMPLIFIED_CHINESE zh_CN
Locale.TRADITIONAL_CHINESE zh_TW
Locale.PRC zh_CN
Locale.TAIWAN zh_TW
Locale.ENGLISH en
Locale.UK en_GB
Locale.US en_US
Locale.FRANCE fr_FR
Locale.FRENCH fr

以下例子是德国locale实例以英语、德语和法语提供了信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class LocaleTest {

public static void main(String[] args) {
Locale deLocale = new Locale("de", "DE");
Locale frLocale = new Locale("fr", "FR");
System.out.println("Default language name (default): "
+ deLocale.getDisplayLanguage());
System.out.println("German language name (German): "
+ deLocale.getDisplayLanguage(deLocale));
System.out.println("German language name (French): "
+ deLocale.getDisplayLanguage(frLocale));
}

}

输出结果为:

1
2
3
Default language name (default): German
German language name (German): Deutsch
German language name (French): allemand

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :