|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
To create aLocaleobject, you typically specify the language code and the country code. For example, to specify the French language and the country of Canada, you would invoke the constructor as follows:The next example createsaLocale = new Locale("fr", "CA");Localeobjects for the English language in the United States and Great Britain:The first argument is the language code, a pair of lowercase letters that conform to ISO-639. You can find a full list of the ISO-639 codes at http://www.ics.uci.edu/pub/ietf/http/related/iso639.txtbLocale = new Locale("en", "US"); cLocale = new Locale("en", "GB");.
The following table lists just a few of the language codes.
Sample Language Codes
Language Code Description deGerman enEnglish frFrench jaJapanese jwJavanese koKorean zhChinese The second argument of the
Localeconstructor is the country code. It consists of two uppercase letters and conforms to ISO-3166. A copy of ISO-3166 can be found at http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html.
The following table contains several sample country codes.
Sample Country Codes
Country Code Description CNChina DEGermany FRFrance INIndia USUnited States If you need to distinguish your
Localefurther, you can specify a third parameter, called the variant code. Usually you specify variant codes to identify differences caused by the computing platform. For example, font differences may force you to use different characters on Windows and UNIX. You could then define theLocaleobjects with the variant codes WINDOWS and UNIX as follows:The variant codes conform to no standard. They are arbitrary and specific to your application. If you createxLocale = new Locale("de", "DE", "UNIX"); yLocale = new Locale("de", "DE", "WINDOWS");Localeobjects with variant codes only your application will know how to deal with them.The country and variant codes are optional. When omitting the country code, you specify a null
String. You may create aLocalefor the English language as follows:enLocale = new Locale("en", "");For your convenience the
Localeclass provides constants for some languages and countries. For example, you can createLocaleobjects by specifying theJAPANESEorJAPANconstants. TheLocaleobjects created by the following two statements are equivalent:j1Locale = Locale.JAPAN; j2Locale = new Locale("ja", "JP");When you specify a language constant, the country portion of the
Localeis undefined. The next two statements create equivalentLocaleobjects:j3Locale = Locale.JAPANESE; j4Locale = new Locale("ja", "");
|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2004 Sun Microsystems, Inc. All rights reserved.