Setting the Locale |
To create aLocale
object, you typically specify the language code and country code. For example, to specify the French language and the country of Canada, you would invoke the constructor as follows:In the next example, we createaLocale = new Locale("fr","CA");Locale
objects for the English language in the U.S.A. and Great Britain:The first argument is the language code, a pair of lower-case letters that conform to ISO-639. You can find a full list of the ISO-639 codes at:bLocale = new Locale("en","US"); cLocale = new Locale("en","GB");The second argument is the country code. It consists of two, upper-case letters, and conforms to ISO3166. A copy of ISO-3166 can be found at:/www.ics.uci.edu/pub/ietf/http/related/iso639.txtIf you need to distinguish yourhttp://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html.Locale
further, you can specify a third parameter, called the variant code. If there are variations in language usage within the same country, you might want to specify a variant. For example, in the South of the United States, people often say "y'all," but in the North they say "you all." You could create different Locale objects as follows:The variant codes conform to no standard. They are arbitrary and application- specific. If you creatednLocale = new Locale("en", "US" ,"NORTH"); sLocale = new Locale("en", "US", "SOUTH");Locale
objects with the NORTH and SOUTH variant codes, as in the preceeding example, only your application would know how to deal with them.Usually, you'll specify variant codes to indentify 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 the
Locale
objects with the variant codes WINDOWS and UNIX:The country and variant codes are optional. You may create axLocale = new Locale("de", "DE" ,"UNIX"); yLocale = new Locale("de", "DE", "WINDOWS");Locale
for the English language as follows:However, if you omit the country code, your application cannot adapt to regional differences in language. For instance, a program using theenLocale = new Locale("en", "");enLocale
object cannot display the word "colour" in the U.K. and the word "color" in the U.S..For your convenience, the
Locale
class provides constants for some languages and countries. For example, you can create Locale objects by specifying theJAPANESE
orJAPAN
constants. TheLocale
objects created by the following two statements are equivalent:When you specify a language constant, the country portion of thej1Locale = Locale.JAPAN; j2Locale = new Locale("ja", "JA");Locale
is undefined. The next two statements create equivalentLocale
objects:j3Locale = Locale.JAPANESE; j4Locale = new Locale("ja", "");
Setting the Locale |