java.util
Class Locale

java.lang.Object
  |
  +--java.util.Locale
All Implemented Interfaces:
Cloneable, Serializable

public final class Locale
extends Object
implements Cloneable, Serializable

Untamed:

See Also:
Serialized Form

Field Summary
static Locale CANADA
          Enabled: Useful constant for country.
static Locale CANADA_FRENCH
          Enabled: Useful constant for country.
static Locale CHINA
          Enabled: Useful constant for country.
static Locale CHINESE
          Enabled: Useful constant for language.
private static String compressedIsoCountries
           
private static String compressedIsoLanguages
           
private  String country
           
private static Locale defaultLocale
           
static Locale ENGLISH
          Enabled: Useful constant for language.
static Locale FRANCE
          Enabled: Useful constant for country.
static Locale FRENCH
          Enabled: Useful constant for language.
static Locale GERMAN
          Enabled: Useful constant for language.
static Locale GERMANY
          Enabled: Useful constant for country.
private  int hashcode
          Placeholder for the object's hash code.
private static String[] isoCountries
          List of all 2-letter country codes currently defined in ISO 3166.
private static String[] isoLanguages
          List of all 2-letter language codes currently defined in ISO 639.
static Locale ITALIAN
          Enabled: Useful constant for language.
static Locale ITALY
          Enabled: Useful constant for country.
static Locale JAPAN
          Enabled: Useful constant for country.
static Locale JAPANESE
          Enabled: Useful constant for language.
static Locale KOREA
          Enabled: Useful constant for country.
static Locale KOREAN
          Enabled: Useful constant for language.
private  String language
           
static Locale PRC
          Enabled: Useful constant for country.
(package private) static long serialVersionUID
          serialization ID
static Locale SIMPLIFIED_CHINESE
          Enabled: Useful constant for language.
static Locale TAIWAN
          Enabled: Useful constant for country.
static Locale TRADITIONAL_CHINESE
          Enabled: Useful constant for language.
static Locale UK
          Enabled: Useful constant for country.
static Locale US
          Enabled: Useful constant for country.
private  String variant
           
 
Constructor Summary
Locale(String language)
          Enabled: Construct a locale from a language code.
Locale(String language, String country)
          Enabled: Construct a locale from language, country.
Locale(String language, String country, String variant)
          Enabled: Construct a locale from language, country, variant.
 
Method Summary
 Object clone()
          Suppressed: Overrides Cloneable
private static String[] composeList(java.text.MessageFormat format, String[] list)
          Given a list of strings, return a list shortened to three elements.
private  String convertOldISOCodes(String language)
           
 boolean equals(Object obj)
          Suppressed: Returns true if this Locale is equal to another object.
private  String findStringMatch(String[][] languages, String desiredLanguage, String fallbackLanguage)
           
private static String formatList(String[] patterns, String[] stringList)
          Format a list with an array of patterns.
static Locale[] getAvailableLocales()
          Enabled: Returns a list of all installed locales.
 String getCountry()
          Enabled: Returns the country/region code for this locale, which will either be the empty string or an upercase ISO 3166 2-letter code.
static Locale getDefault()
          Enabled: Gets the current value of the default locale for this instance of the Java Virtual Machine.
 String getDisplayCountry()
          Enabled: Returns a name for the locale's country that is appropriate for display to the user.
 String getDisplayCountry(Locale inLocale)
          Enabled: Returns a name for the locale's country that is appropriate for display to the user.
 String getDisplayLanguage()
          Enabled: Returns a name for the locale's language that is appropriate for display to the user.
 String getDisplayLanguage(Locale inLocale)
          Enabled: Returns a name for the locale's language that is appropriate for display to the user.
 String getDisplayName()
          Enabled: Returns a name for the locale that is appropriate for display to the user.
 String getDisplayName(Locale inLocale)
          Enabled: Returns a name for the locale that is appropriate for display to the user.
 String getDisplayVariant()
          Enabled: Returns a name for the locale's variant code that is appropriate for display to the user.
 String getDisplayVariant(Locale inLocale)
          Enabled: Returns a name for the locale's variant code that is appropriate for display to the user.
private  String[] getDisplayVariantArray(ResourceBundle bundle)
          Return an array of the display names of the variant.
 String getISO3Country()
          Enabled: Returns a three-letter abbreviation for this locale's country.
 String getISO3Language()
          Enabled: Returns a three-letter abbreviation for this locale's language.
static String[] getISOCountries()
          Enabled: Returns a list of all 2-letter country codes defined in ISO 3166.
static String[] getISOLanguages()
          Enabled: Returns a list of all 2-letter language codes defined in ISO 639.
 String getLanguage()
          Enabled: Returns the language code for this locale, which will either be the empty string or a lowercase ISO 639 code.
 String getVariant()
          Enabled: Returns the variant code for this locale.
 int hashCode()
          Suppressed: Override hashCode.
private  void readObject(ObjectInputStream in)
           
static void setDefault(Locale newLocale)
          Enabled: Sets the default locale for this instance of the Java Virtual Machine.
private  String toLowerCase(String str)
           
 String toString()
          Suppressed: Getter for the programmatic name of the entire locale, with the language, country and variant separated by underbars.
private  String toUpperCase(String str)
           
private  void writeObject(ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ENGLISH

public static final Locale ENGLISH
Enabled: Useful constant for language.


FRENCH

public static final Locale FRENCH
Enabled: Useful constant for language.


GERMAN

public static final Locale GERMAN
Enabled: Useful constant for language.


ITALIAN

public static final Locale ITALIAN
Enabled: Useful constant for language.


JAPANESE

public static final Locale JAPANESE
Enabled: Useful constant for language.


KOREAN

public static final Locale KOREAN
Enabled: Useful constant for language.


CHINESE

public static final Locale CHINESE
Enabled: Useful constant for language.


SIMPLIFIED_CHINESE

public static final Locale SIMPLIFIED_CHINESE
Enabled: Useful constant for language.


TRADITIONAL_CHINESE

public static final Locale TRADITIONAL_CHINESE
Enabled: Useful constant for language.


FRANCE

public static final Locale FRANCE
Enabled: Useful constant for country.


GERMANY

public static final Locale GERMANY
Enabled: Useful constant for country.


ITALY

public static final Locale ITALY
Enabled: Useful constant for country.


JAPAN

public static final Locale JAPAN
Enabled: Useful constant for country.


KOREA

public static final Locale KOREA
Enabled: Useful constant for country.


CHINA

public static final Locale CHINA
Enabled: Useful constant for country.


PRC

public static final Locale PRC
Enabled: Useful constant for country.


TAIWAN

public static final Locale TAIWAN
Enabled: Useful constant for country.


UK

public static final Locale UK
Enabled: Useful constant for country.


US

public static final Locale US
Enabled: Useful constant for country.


CANADA

public static final Locale CANADA
Enabled: Useful constant for country.


CANADA_FRENCH

public static final Locale CANADA_FRENCH
Enabled: Useful constant for country.


serialVersionUID

static final long serialVersionUID
serialization ID


language

private String language
See Also:
getLanguage()

country

private String country
See Also:
getCountry()

variant

private String variant
See Also:
getVariant()

hashcode

private int hashcode
Placeholder for the object's hash code. Always -1.


defaultLocale

private static Locale defaultLocale

isoLanguages

private static String[] isoLanguages
List of all 2-letter language codes currently defined in ISO 639. (Because the Java VM specification turns an array constant into executable code that generates the array element by element, we keep the array in compressed form in a single string and build the array from it at run time when requested.) [We're now also using this table to store a mapping from 2-letter ISO language codes to 3-letter ISO language codes. Each group of characters consists of a comma, a 2-letter code, and a 3-letter code. We look up a 3-letter code by searching for a comma followed by a 2-letter code and then getting the three letters following the 2-letter code.]


compressedIsoLanguages

private static final String compressedIsoLanguages

isoCountries

private static String[] isoCountries
List of all 2-letter country codes currently defined in ISO 3166. (Because the Java VM specification turns an array constant into executable code that generates the array element by element, we keep the array in compressed form in a single string and build the array from it at run time when requested.) [We're now also using this table to store a mapping from 2-letter ISO country codes to 3-letter ISO country codes. Each group of characters consists of a comma, a 2-letter code, and a 3-letter code. We look up a 3-letter code by searching for a comma followed by a 2-letter code and then getting the three letters following the 2-letter code.]


compressedIsoCountries

private static final String compressedIsoCountries
Constructor Detail

Locale

public Locale(String language,
              String country,
              String variant)
Enabled: Construct a locale from language, country, variant. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed. This constructor accepts both the old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other API on Locale will return only the OLD codes.

Parameters:
language - lowercase two-letter ISO-639 code.
country - uppercase two-letter ISO-3166 code.
variant - vendor and browser specific code. See class description.

Locale

public Locale(String language,
              String country)
Enabled: Construct a locale from language, country. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed. This constructor accepts both the old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other API on Locale will return only the OLD codes.

Parameters:
language - lowercase two-letter ISO-639 code.
country - uppercase two-letter ISO-3166 code.

Locale

public Locale(String language)
Enabled: Construct a locale from a language code. NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically iw, ji, and in) have changed. This constructor accepts both the old codes (iw, ji, and in) and the new codes (he, yi, and id), but all other API on Locale will return only the OLD codes.

Parameters:
language - lowercase two-letter ISO-639 code.
Since:
1.4
Method Detail

getDefault

public static Locale getDefault()
Enabled: Gets the current value of the default locale for this instance of the Java Virtual Machine.

The Java Virtual Machine sets the default locale during startup based on the host environment. It is used by many locale-sensitive methods if no locale is explicitly specified. It can be changed using the setDefault method.

Returns:
the default locale for this instance of the Java Virtual Machine

setDefault

public static void setDefault(Locale newLocale)
Enabled: Sets the default locale for this instance of the Java Virtual Machine. This does not affect the host locale.

If there is a security manager, its checkPermission method is called with a PropertyPermission("user.language", "write") permission before the default locale is changed.

The Java Virtual Machine sets the default locale during startup based on the host environment. It is used by many locale-sensitive methods if no locale is explicitly specified.

Since changing the default locale may affect many different areas of functionality, this method should only be used if the caller is prepared to reinitialize locale-sensitive code running within the same Java Virtual Machine, such as the user interface.

Parameters:
newLocale - the new default locale
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow the operation.
NullPointerException - if newLocale is null
See Also:
SecurityManager.checkPermission(java.security.Permission), java.util.PropertyPermission

getAvailableLocales

public static Locale[] getAvailableLocales()
Enabled: Returns a list of all installed locales.


getISOCountries

public static String[] getISOCountries()
Enabled: Returns a list of all 2-letter country codes defined in ISO 3166. Can be used to create Locales.


getISOLanguages

public static String[] getISOLanguages()
Enabled: Returns a list of all 2-letter language codes defined in ISO 639. Can be used to create Locales. [NOTE: ISO 639 is not a stable standard-- some languages' codes have changed. The list this function returns includes both the new and the old codes for the languages whose codes have changed.]


getLanguage

public String getLanguage()
Enabled: Returns the language code for this locale, which will either be the empty string or a lowercase ISO 639 code.

NOTE: ISO 639 is not a stable standard-- some languages' codes have changed. Locale's constructor recognizes both the new and the old codes for the languages whose codes have changed, but this function always returns the old code. If you want to check for a specific language whose code has changed, don't do

 if (locale.getLanguage().equals("he")
    ...
 
Instead, do
 if (locale.getLanguage().equals(new Locale("he", "", "").getLanguage())
    ...

See Also:
getDisplayLanguage()

getCountry

public String getCountry()
Enabled: Returns the country/region code for this locale, which will either be the empty string or an upercase ISO 3166 2-letter code.

See Also:
getDisplayCountry()

getVariant

public String getVariant()
Enabled: Returns the variant code for this locale.

See Also:
getDisplayVariant()

toString

public final String toString()
Suppressed: Getter for the programmatic name of the entire locale, with the language, country and variant separated by underbars. Language is always lower case, and country is always upper case. If the language is missing, the string will begin with an underbar. If both the language and country fields are missing, this function will return the empty string, even if the variant field is filled in (you can't have a locale with just a variant-- the variant must accompany a valid language or country code). Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC"

Overrides:
toString in class Object
Returns:
a string representation of the object.
See Also:
getDisplayName()

getISO3Language

public String getISO3Language()
                       throws MissingResourceException
Enabled: Returns a three-letter abbreviation for this locale's language. If the locale doesn't specify a language, this will be the empty string. Otherwise, this will be a lowercase ISO 639-2/T language code. The ISO 639-2 language codes can be found on-line at ftp://dkuug.dk/i18n/iso-639-2.txt

MissingResourceException

getISO3Country

public String getISO3Country()
                      throws MissingResourceException
Enabled: Returns a three-letter abbreviation for this locale's country. If the locale doesn't specify a country, this will be tbe the empty string. Otherwise, this will be an uppercase ISO 3166 3-letter country code.

MissingResourceException

getDisplayLanguage

public final String getDisplayLanguage()
Enabled: Returns a name for the locale's language that is appropriate for display to the user. If possible, the name returned will be localized for the default locale. For example, if the locale is fr_FR and the default locale is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and the default locale is fr_FR, getDisplayLanguage() will return "anglais". If the name returned cannot be localized for the default locale, (say, we don't have a Japanese name for Croatian), this function falls back on the English name, and uses the ISO code as a last-resort value. If the locale doesn't specify a language, this function returns the empty string.


getDisplayLanguage

public String getDisplayLanguage(Locale inLocale)
Enabled: Returns a name for the locale's language that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale. For example, if the locale is fr_FR and inLocale is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and inLocale is fr_FR, getDisplayLanguage() will return "anglais". If the name returned cannot be localized according to inLocale, (say, we don't have a Japanese name for Croatian), this function falls back on the default locale, on the English name, and finally on the ISO code as a last-resort value. If the locale doesn't specify a language, this function returns the empty string.


getDisplayCountry

public final String getDisplayCountry()
Enabled: Returns a name for the locale's country that is appropriate for display to the user. If possible, the name returned will be localized for the default locale. For example, if the locale is fr_FR and the default locale is en_US, getDisplayCountry() will return "France"; if the locale is en_US and the default locale is fr_FR, getDisplayLanguage() will return "Etats-Unis". If the name returned cannot be localized for the default locale, (say, we don't have a Japanese name for Croatia), this function falls back on the English name, and uses the ISO code as a last-resort value. If the locale doesn't specify a country, this function returns the empty string.


getDisplayCountry

public String getDisplayCountry(Locale inLocale)
Enabled: Returns a name for the locale's country that is appropriate for display to the user. If possible, the name returned will be localized according to inLocale. For example, if the locale is fr_FR and inLocale is en_US, getDisplayCountry() will return "France"; if the locale is en_US and inLocale is fr_FR, getDisplayLanguage() will return "Etats-Unis". If the name returned cannot be localized according to inLocale. (say, we don't have a Japanese name for Croatia), this function falls back on the default locale, on the English name, and finally on the ISO code as a last-resort value. If the locale doesn't specify a country, this function returns the empty string.


getDisplayVariant

public final String getDisplayVariant()
Enabled: Returns a name for the locale's variant code that is appropriate for display to the user. If possible, the name will be localized for the default locale. If the locale doesn't specify a variant code, this function returns the empty string.


getDisplayVariant

public String getDisplayVariant(Locale inLocale)
Enabled: Returns a name for the locale's variant code that is appropriate for display to the user. If possible, the name will be localized for inLocale. If the locale doesn't specify a variant code, this function returns the empty string.


getDisplayName

public final String getDisplayName()
Enabled: Returns a name for the locale that is appropriate for display to the user. This will be the values returned by getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() assembled into a single string. The display name will have one of the following forms:

language (country, variant)

language (country)

language (variant)

country (variant)

language

country

variant

depending on which fields are specified in the locale. If the language, country, and variant fields are all empty, this function returns the empty string.


getDisplayName

public String getDisplayName(Locale inLocale)
Enabled: Returns a name for the locale that is appropriate for display to the user. This will be the values returned by getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() assembled into a single string. The display name will have one of the following forms:

language (country, variant)

language (country)

language (variant)

country (variant)

language

country

variant

depending on which fields are specified in the locale. If the language, country, and variant fields are all empty, this function returns the empty string.


clone

public Object clone()
Suppressed: Overrides Cloneable

Overrides:
clone in class Object
Returns:
a clone of this instance.
See Also:
java.lang.Cloneable

hashCode

public int hashCode()
Suppressed: Override hashCode. Since Locales are often used in hashtables, caches the value for speed.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
java.lang.Object#equals(java.lang.Object), java.util.Hashtable

equals

public boolean equals(Object obj)
Suppressed: Returns true if this Locale is equal to another object. A Locale is deemed equal to another Locale with identical language, country, and variant, and unequal to all other objects.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this Locale is equal to the specified object.
See Also:
Object.hashCode(), java.util.Hashtable

getDisplayVariantArray

private String[] getDisplayVariantArray(ResourceBundle bundle)
Return an array of the display names of the variant.

Parameters:
bundle - the ResourceBundle to use to get the display names
Returns:
an array of display names, possible of zero length.

formatList

private static String formatList(String[] patterns,
                                 String[] stringList)
Format a list with an array of patterns.

Parameters:
patterns - an array of three patterns. The first pattern is not used. The second pattern should create a MessageFormat taking 0-3 arguments and formatting them into a list. The third pattern should take 2 arguments and is used by composeList. If patterns is null, then a the list is formatted by concatenation with the delimiter ','.
stringList - the list of strings to be formatted.
Returns:
a string representing the list.

composeList

private static String[] composeList(java.text.MessageFormat format,
                                    String[] list)
Given a list of strings, return a list shortened to three elements. Shorten it by applying the given format to the first two elements recursively.

Parameters:
format - a format which takes two arguments
list - a list of strings
Returns:
if the list is three elements or shorter, the same list; otherwise, a new list of three elements.

writeObject

private void writeObject(ObjectOutputStream out)
                  throws IOException
IOException

readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
IOException
ClassNotFoundException

toLowerCase

private String toLowerCase(String str)

toUpperCase

private String toUpperCase(String str)

findStringMatch

private String findStringMatch(String[][] languages,
                               String desiredLanguage,
                               String fallbackLanguage)

convertOldISOCodes

private String convertOldISOCodes(String language)


comments?