public class Locale extends java.lang.Object implements java.lang.Comparable<Locale>
Locale
object represents a specific geographical, political, or cultural region.
Like the original java.util.Locale
class this one adds some finer handling with
languages, countries, and variants. The original class only supports the ISO 639-1 language
codes (two letters), this class also adds support for ISO 639-2 language codes (three letters).
This allows applications for finer localization. Especially if software authors want to
publish a program translated in Lower German (code "nds") this would only be possible with
the default locale "de_DE_nds" or some kind of construction abusing the variant part. Since
most languages of the world have ISO 639-2 codes this standard seems the best choice. To be
fair for most applications ISO 639-1 codes are OK. For this reason the country codes are
supported as known from the java.util.Locale
class (two uppercase letters).
In most cases it should be possible to convert between this class and the default SUN
implementation.
If you like to let your application support Lower German labels you can use "nds_DE" for
the common case. If there are variants for example for different regions you can deploy
the variant part like "nds_DE_Vechta", "nds_DE_Oldenburg", and so on. You can use whatever
you want as variant, possibly you want to have a multipart variant like the locale id defined
by the ISO 3166-2 for Germany "nds_DE_NI_Vechta", "nds_DE_NI_Oldenburg", "nds_DE_MV_Stralsund".
Remember that the variant part is application specific, while the language and country codes
supported by this class are standard values updated from time to time (or war to war).
To make programmer's life easier this class provides several methods to parse directory and
file names in order to automatically detect available localizations for programs.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
country
The country according to ISO 3166-1 (two letters).
|
protected static java.lang.String[] |
iso3166_1
The countries array according to ISO 3166-1 (two letters).
|
protected static java.lang.String[] |
iso639_1
The languages array according to ISO 639-1 (two letters).
|
protected static java.lang.String[] |
iso639_2
The languages array according to ISO 639-2 (three letters) including synonyms.
|
protected static java.lang.String[][] |
iso639_syns
The two-dimensional array holding the synonym groups defined by ISO 639-1/2.
|
protected java.lang.String |
language
The language according to either ISO 639-1 (two letters) or ISO 639-2 (three letters).
|
protected java.lang.String |
variant
The application specific variant representing some fine grained regional specification.
|
Constructor and Description |
---|
Locale()
Constructor method for i18n purposes only.
|
Locale(java.lang.String language)
Constructor method.
|
Locale(java.lang.String language,
java.lang.String country)
Constructor method.
|
Locale(java.lang.String language,
java.lang.String country,
java.lang.String variant)
Constructor method.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Locale other)
Compares this object with the specified object for order.
|
boolean |
equals(java.lang.Object obj)
Returns
true if this Locale is equal to another object. |
java.lang.String |
getCountry()
Returns the country according to ISO 3166-1 (two letters).
|
static java.util.Locale |
getJavaLocale(Locale locale)
Provides a default Java for a Commons locale.
|
static java.lang.String |
getJavaLocaleForDisplay(java.util.Locale locale,
Locale userlocale)
Provides a natural language string representation for a Java locale.
|
java.lang.String |
getLanguage()
Returns the language according to ISO 639-1 (two letters) or ISO 639-2 (three letters).
|
static java.lang.String |
getLocaleForDisplay(Locale locale,
Locale userlocale)
Provides a natural language string representation for a locale.
|
static java.util.Vector<Locale> |
getLocaleSynonyms(Locale locale)
Returns a list of locales which are language synonyms defined by ISO 639-1/2.
|
java.lang.String |
getVariant()
Returns the application specific variant representing some fine grained regional specification.
|
int |
hashCode()
Computes hash code for containers like
Hashtable . |
static Locale |
parseLocale(java.lang.String id)
Returns the composed string representation with language, country, and variant.
|
java.lang.String |
toString()
Returns the composed string representation with language, country, and variant.
|
static java.lang.String |
toString(java.lang.String language,
java.lang.String country,
java.lang.String variant)
Returns the composed string representation with language, country, and variant.
|
protected static final java.lang.String[] iso3166_1
CountryCodes
data basis using the TestLocale.main()
method.protected static final java.lang.String[] iso639_1
LanguageCodes
data basis using the TestLocale.main()
method.protected static final java.lang.String[] iso639_2
LanguageCodes
data basis using the TestLocale.main()
method.protected static final java.lang.String[][] iso639_syns
LanguageCodes
data basis using the TestLocale.main()
method.protected java.lang.String language
protected java.lang.String country
protected java.lang.String variant
public Locale() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic Locale(java.lang.String language)
language
- The language according to either ISO 639-1 (two letters) or ISO 639-2 (three letters)java.lang.NullPointerException
- Error indicationjava.lang.IllegalArgumentException
- Error indicationpublic Locale(java.lang.String language, java.lang.String country)
language
- The language according to either ISO 639-1 (two letters) or ISO 639-2 (three letters)country
- The country according to ISO 3166-1 (two letters)java.lang.NullPointerException
- Error indicationjava.lang.IllegalArgumentException
- Error indicationpublic Locale(java.lang.String language, java.lang.String country, java.lang.String variant)
language
- The language according to either ISO 639-1 (two letters) or ISO 639-2 (three letters)country
- The country according to ISO 3166-1 (two letters)variant
- The application specific variant representing some fine grained regional specificationjava.lang.NullPointerException
- Error indicationjava.lang.IllegalArgumentException
- Error indicationpublic java.lang.String getLanguage()
public java.lang.String getCountry()
public java.lang.String getVariant()
public boolean equals(java.lang.Object obj)
true
if this Locale is equal to another object.
equals
in class java.lang.Object
public java.lang.String toString()
java.util.Locale
class the parts are separated with "_" characters.
While the language and country codes are standardized the optional variant may have
any lexical structure but should be of the form "[Text]_[Text]_...".
toString
in class java.lang.Object
parseLocale(String)
public static java.lang.String toString(java.lang.String language, java.lang.String country, java.lang.String variant)
java.util.Locale
class the parts are separated with "_" characters.
While the language and country codes are standardized the optional variant may have
any lexical structure but should be of the form "[Text]_[Text]_...".
language
- The languagecountry
- The country (optional)variant
- The variant (optional)public int compareTo(Locale other)
compareTo
in interface java.lang.Comparable<Locale>
other
- The locale to be comparedpublic int hashCode()
Hashtable
.
hashCode
in class java.lang.Object
public static Locale parseLocale(java.lang.String id)
java.util.Locale
class the parts are separated with "_" characters.
While the language and country codes are standardized the optional variant may have
any lexical structure but should be of the form "[Text]_[Text]_...".
For example the id "nds_DE_NI_Vechta_Süd" is parsed as language "nds", country "DE",
variant "NI_Vechta_Süd".
id
- The string to be parsedjava.lang.NullPointerException
- Error indicationjava.lang.IllegalArgumentException
- Error indicationtoString()
public static java.util.Vector<Locale> getLocaleSynonyms(Locale locale)
I18NUtils.getLocaleSynonyms(Locale)
uses.
locale
- The locale for thich to return the synonyms, may not be null
java.lang.NullPointerException
- Error indicationI18NUtils.getLocaleSynonyms(Locale)
public static java.lang.String getLocaleForDisplay(Locale locale, Locale userlocale)
locale
- The locale to be displayeduserlocale
- The display localejava.lang.NullPointerException
- Error indicationpublic static java.lang.String getJavaLocaleForDisplay(java.util.Locale locale, Locale userlocale)
locale
- The Java locale to be displayeduserlocale
- The display localejava.lang.NullPointerException
- Error indicationpublic static java.util.Locale getJavaLocale(Locale locale)
locale
- The locale to be convertednull
if not availablejava.lang.NullPointerException
- Error indicationCopyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.