java.util
Class Locale
- Cloneable, Serializable
Locales represent a specific country and culture. Classes which can be
passed a Locale object tailor their information for a given locale. For
instance, currency number formatting is handled differently for the USA
and France.
Locales are made up of a language code, a country code, and an optional
set of variant strings. Language codes are represented by
ISO 639:1988 w/ additions from ISO 639/RA Newsletter No. 1/1989
and a decision of the Advisory Committee of ISO/TC39 on August 8, 1997.
Country codes are represented by
ISO 3166. Variant strings are vendor and browser specific. Standard
variant strings include "POSIX" for POSIX, "WIN" for MS-Windows, and
"MAC" for Macintosh. When there is more than one variant string, they must
be separated by an underscore (U+005F).
The default locale is determined by the values of the system properties
user.language, user.country (or user.region), and user.variant, defaulting
to "en_US". Note that the locale does NOT contain the conversion and
formatting capabilities (for that, use ResourceBundle and java.text).
Rather, it is an immutable tag object for identifying a given locale, which
is referenced by these other classes when they must make locale-dependent
decisions.
static Locale | CANADA - Locale which represents the English speaking portion of Canada.
|
static Locale | CANADA_FRENCH - Locale which represents the French speaking portion of Canada.
|
static Locale | CHINA - Locale which represents China.
|
static Locale | CHINESE - Locale which represents the Chinese language.
|
static Locale | ENGLISH - Locale which represents the English language.
|
static Locale | FRANCE - Locale which represents France.
|
static Locale | FRENCH - Locale which represents the French language.
|
static Locale | GERMAN - Locale which represents the German language.
|
static Locale | GERMANY - Locale which represents Germany.
|
static Locale | ITALIAN - Locale which represents the Italian language.
|
static Locale | ITALY - Locale which represents Italy.
|
static Locale | JAPAN - Locale which represents Japan.
|
static Locale | JAPANESE - Locale which represents the Japanese language.
|
static Locale | KOREA - Locale which represents Korea.
|
static Locale | KOREAN - Locale which represents the Korean language.
|
static Locale | PRC - Locale which represents the People's Republic of China.
|
static Locale | ROOT - The root locale, used as the base case in lookups by
locale-sensitive operations.
|
static Locale | SIMPLIFIED_CHINESE - Locale which represents the Chinese language as used in China.
|
static Locale | TAIWAN - Locale which represents Taiwan.
|
static Locale | TRADITIONAL_CHINESE - Locale which represents the Chinese language as used in Taiwan.
|
static Locale | UK - Locale which represents the United Kingdom.
|
static Locale | US - Locale which represents the United States.
|
Locale(String language) - Creates a new locale for a language.
|
Locale(String language, String country) - Creates a new locale for the given language and country.
|
Locale(String language, String country, String variant) - Creates a new locale for the given language and country.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
CANADA
public static final Locale CANADA
Locale which represents the English speaking portion of Canada.
CANADA_FRENCH
public static final Locale CANADA_FRENCH
Locale which represents the French speaking portion of Canada.
CHINA
public static final Locale CHINA
Locale which represents China.
Same as SIMPLIFIED_CHINESE Locale.
CHINESE
public static final Locale CHINESE
Locale which represents the Chinese language.
ENGLISH
public static final Locale ENGLISH
Locale which represents the English language.
FRANCE
public static final Locale FRANCE
Locale which represents France.
FRENCH
public static final Locale FRENCH
Locale which represents the French language.
GERMAN
public static final Locale GERMAN
Locale which represents the German language.
GERMANY
public static final Locale GERMANY
Locale which represents Germany.
ITALIAN
public static final Locale ITALIAN
Locale which represents the Italian language.
ITALY
public static final Locale ITALY
Locale which represents Italy.
JAPAN
public static final Locale JAPAN
Locale which represents Japan.
JAPANESE
public static final Locale JAPANESE
Locale which represents the Japanese language.
KOREA
public static final Locale KOREA
Locale which represents Korea.
KOREAN
public static final Locale KOREAN
Locale which represents the Korean language.
PRC
public static final Locale PRC
Locale which represents the People's Republic of China.
Same as CHINA Locale.
ROOT
public static final Locale ROOT
The root locale, used as the base case in lookups by
locale-sensitive operations.
SIMPLIFIED_CHINESE
public static final Locale SIMPLIFIED_CHINESE
Locale which represents the Chinese language as used in China.
TAIWAN
public static final Locale TAIWAN
Locale which represents Taiwan.
Same as TRADITIONAL_CHINESE Locale.
TRADITIONAL_CHINESE
public static final Locale TRADITIONAL_CHINESE
Locale which represents the Chinese language as used in Taiwan.
Same as TAIWAN Locale.
UK
public static final Locale UK
Locale which represents the United Kingdom.
US
public static final Locale US
Locale which represents the United States.
Locale
public Locale(String language)
Creates a new locale for a language.
language
- lowercase two-letter ISO-639 A2 language code
Locale
public Locale(String language,
String country)
Creates a new locale for the given language and country.
language
- lowercase two-letter ISO-639 A2 language codecountry
- uppercase two-letter ISO-3166 A2 country code
Locale
public Locale(String language,
String country,
String variant)
Creates a new locale for the given language and country.
language
- lowercase two-letter ISO-639 A2 language codecountry
- uppercase two-letter ISO-3166 A2 contry codevariant
- vendor and browser specific
clone
public Object clone()
Does the same as Object.clone()
but does not throw
a CloneNotSupportedException
. Why anyone would
use this method is a secret to me, since this class is immutable.
- clone in interface Object
equals
public boolean equals(Object obj)
Compares two locales. To be equal, obj must be a Locale with the same
language, country, and variant code.
- equals in interface Object
- true if obj is equal to this
getCountry
public String getCountry()
Returns the country code of this locale.
- country code portion of this locale, or an empty String
getDefault
public static Locale getDefault()
Returns the default Locale. The default locale is generally once set
on start up and then never changed. Normally you should use this locale
for everywhere you need a locale. The initial setting matches the
default locale, the user has chosen.
- the default locale for this virtual machine
getDisplayCountry
public String getDisplayCountry()
Returns the country name of this locale localized to the
default locale. If the localized is not found, the ISO code
is returned. This has the same effect as
getDisplayCountry(Locale.getDefault());
- the country name of this locale localized to the given locale,
with the ISO code as backup
getDisplayCountry
public String getDisplayCountry(Locale inLocale)
Gets the name of the country specified by this locale, in a form suitable
for display to the user. If possible, the display name will be localized
to the specified locale. For example, if the locale instance is
Locale.GERMANY
, and the specified locale is
Locale.UK
,
the result would be 'Germany'. Using the German locale would instead give
'Deutschland'. If the display name can not be localized to the supplied
locale, it will fall back on other output in the following order:
- the display name in the default locale
- the display name in English
- the ISO code
If the country is unspecified by this locale, then the empty string is
returned.
inLocale
- the locale to use for formatting the display string.
- the country name of this locale localized to the given locale,
with the default locale, English and the ISO code as backups.
getDisplayLanguage
public String getDisplayLanguage()
Gets the country name suitable for display to the user, formatted
for the default locale. This has the same effect as
getDisplayLanguage(Locale.getDefault());
- the language name of this locale localized to the default locale,
with the ISO code as backup
getDisplayLanguage
public String getDisplayLanguage(Locale inLocale)
Gets the name of the language specified by this locale, in a form suitable
for display to the user. If possible, the display name will be localized
to the specified locale. For example, if the locale instance is
Locale.GERMANY
, and the specified locale is
Locale.UK
,
the result would be 'German'. Using the German locale would instead give
'Deutsch'. If the display name can not be localized to the supplied
locale, it will fall back on other output in the following order:
- the display name in the default locale
- the display name in English
- the ISO code
If the language is unspecified by this locale, then the empty string is
returned.
inLocale
- the locale to use for formatting the display string.
- the language name of this locale localized to the given locale,
with the default locale, English and the ISO code as backups.
getDisplayName
public String getDisplayName()
Gets all local components suitable for display to the user, formatted
for the default locale. For the language component, getDisplayLanguage
is called. For the country component, getDisplayCountry is called.
For the variant set component, getDisplayVariant is called.
The returned String will be one of the following forms:
language (country, variant)
language (country)
language (variant)
country (variant)
language
country
variant
- String version of this locale, suitable for display to the user
getDisplayName
public String getDisplayName(Locale locale)
Gets all local components suitable for display to the user, formatted
for a specified locale. For the language component,
getDisplayLanguage(Locale) is called. For the country component,
getDisplayCountry(Locale) is called. For the variant set component,
getDisplayVariant(Locale) is called.
The returned String will be one of the following forms:
language (country, variant)
language (country)
language (variant)
country (variant)
language
country
variant
locale
- locale to use for formatting
- String version of this locale, suitable for display to the user
getDisplayVariant
public String getDisplayVariant()
Returns the variant name of this locale localized to the
default locale. If the localized is not found, the variant code
itself is returned. This has the same effect as
getDisplayVariant(Locale.getDefault());
- the variant code of this locale localized to the given locale,
with the ISO code as backup
getDisplayVariant
public String getDisplayVariant(Locale inLocale)
Gets the name of the variant specified by this locale, in a form suitable
for display to the user. If possible, the display name will be localized
to the specified locale. For example, if the locale instance is a revised
variant, and the specified locale is
Locale.UK
, the result
would be 'REVISED'. Using the German locale would instead give
'Revidiert'. If the display name can not be localized to the supplied
locale, it will fall back on other output in the following order:
- the display name in the default locale
- the display name in English
- the ISO code
If the variant is unspecified by this locale, then the empty string is
returned.
inLocale
- the locale to use for formatting the display string.
- the variant name of this locale localized to the given locale,
with the default locale, English and the ISO code as backups.
getISO3Country
public String getISO3Country()
Returns the three-letter ISO country abbrevation of the locale.
getISO3Language
public String getISO3Language()
Returns the three-letter ISO language abbrevation of this locale.
getISOCountries
public static String[] getISOCountries()
Returns a list of all 2-letter uppercase country codes as defined
in ISO 3166.
- a list of acceptable country codes
getISOLanguages
public static String[] getISOLanguages()
Returns a list of all 2-letter lowercase language codes as defined
in ISO 639 (both old and new variant).
- a list of acceptable language codes
getLanguage
public String getLanguage()
Returns the language code of this locale. Some language codes have changed
as ISO 639 has evolved; this returns the old name, even if you built
the locale with the new one.
- language code portion of this locale, or an empty String
getVariant
public String getVariant()
Returns the variant code of this locale.
- the variant code portion of this locale, or an empty String
hashCode
public int hashCode()
Return the hash code for this locale. The hashcode is the logical
xor of the hash codes of the language, the country and the variant.
The hash code is precomputed, since Locale
s are often
used in hash tables.
- hashCode in interface Object
setDefault
public static void setDefault(Locale newLocale)
Changes the default locale. Normally only called on program start up.
Note that this doesn't change the locale for other programs. This has
a security check,
PropertyPermission("user.language", "write")
, because of
its potential impact to running code.
newLocale
- the new default locale
toString
public String toString()
Gets the string representation of the current locale. This consists of
the language, the country, and the variant, separated by an underscore.
The variant is listed only if there is a language or country. Examples:
"en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC".
- toString in interface Object
- the string representation of this Locale
Locale.java -- i18n locales
Copyright (C) 1998, 1999, 2001, 2002, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.