Working with MS VM
 In this topic

*Constructors

*Methods

*Fields

 

Internationalization   PreviousThis Package
Package java.util   Previous This
Package

 


Class Locale

public final class Locale implements Cloneable, Serializable
{
  // Fields
  static public final Locale AFRIKAANS;
  static public final Locale ALBANIAN;
  static public final Locale AUSTRALIA;
  static public final Locale BASQUE;
  static public final Locale BELGIAN;
  static public final Locale BELGIAN_FRENCH;
  static public final Locale BRAZILIAN;
  static public final Locale BULGARIAN;
  static public final Locale BYELORUS;
  static public final Locale CANADA;
  static public final Locale CANADA_FRENCH;
  static public final Locale CATALAN;
  static public final Locale CHINA;
  static public final Locale CHINESE;
  static public final Locale CROATIAN;
  static public final Locale CZECH;
  static public final Locale DANISH;
  static public final Locale DUTCH;
  static public final Locale ENGLISH;
  static public final Locale ESTONIAN;
  static public final Locale FINNISH;
  static public final Locale FRANCE;
  static public final Locale FRENCH;
  static public final Locale GERMAN;
  static public final Locale GERMAN_AUSTRIAN;
  static public final Locale GERMAN_SWISS;
  static public final Locale GERMANY;
  static public final Locale GREEK;
  static public final Locale HEBREW;
  static public final Locale HUNGARIAN;
  static public final Locale ICELANDIC;
  static public final Locale INDONESIAN;
  static public final Locale IRELAND;
  static public final Locale ITALIAN;
  static public final Locale ITALY;
  static public final Locale JAPAN;
  static public final Locale JAPANESE;
  static public final Locale JAPANESE_VERTICAL;
  static public final Locale KOREA;
  static public final Locale KOREAN;
  static public final Locale KOREAN_VERTICAL;
  static public final Locale LATVIAN;
  static public final Locale LITHUANIAN;
  static public final Locale MEXICAN;
  static public final Locale NEWZEALAND;
  static public final Locale NORWEGIAN;
  static public final Locale NORWEGIAN_NYNORSK;
  static public final Locale POLISH;
  static public final Locale PORTUGESE;
  static public final Locale PRC;
  static public final Locale ROMANIAN;
  static public final Locale RUSSIAN;
  static public final Locale SERBIAN;
  static public final Locale SIMPLIFIED_CHINESE;
  static public final Locale SIMPLIFIED_CHINESE_VERTICAL;
  static public final Locale SINGAPORE;
  static public final Locale SLOVAKIAN;
  static public final Locale SLOVENIAN;
  static public final Locale SOUTH_AFRICA;
  static public final Locale SPANISH;
  static public final Locale SPANISH_MODERN;
  static public final Locale SWEDISH;
  static public final Locale SWISS;
  static public final Locale TAIWAN;
  static public final Locale THAI;
  static public final Locale TRADITIONAL_CHINESE;
  static public final Locale TRADITIONAL_CHINESE_VERTICAL;
  static public final Locale TURKISH;
  static public final Locale UK;
  static public final Locale UKRANIAN;
  static public final Locale US;

  // Constructors
  public Locale(String language, String country, String variant);
  public Locale(String language, String country, String variant, int LCID,
        int codepage);
  public Locale(String language, String country);

  // Methods
  public Object clone();
  public boolean equals(Object obj);
  public int getCodePage();
  public String getCountry();
  public static synchronized Locale getDefault();
  public Locale[] getDefaultLocaleList();
  public final String getDisplayCountry();
  public String getDisplayCountry(Locale inLocale);
  public final String getDisplayLanguage();
  public String getDisplayLanguage(Locale inLocale);
  public final String getDisplayName();
  public String getDisplayName(Locale inLocale);
  public final String getDisplayVariant();
  public String getDisplayVariant(Locale inLocale);
  public String getISO3Country() throws MissingResourceException;
  public String getISO3Language() throws MissingResourceException;
  public String getLanguage();
  public int getLCID() throws MissingResourceException;
  public static Locale getLocaleFromLCID(int lcid);
  public String getVariant();
  public synchronized int hashCode();
  public static synchronized void setDefault(Locale newLocale);
  public final String toString();
}

A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user. For example, displaying a number is a locale-sensitive operation--the number should be formatted according to the customs/conventions of the user's native country, region, or culture.

You create a Locale object using one of the constructors in this class:


Locale(String language, String country)
Locale(String language, String country, String variant)
Locale(String language, String country, String variant, int LCID, int codepage)

The first argument to both constructors is a valid ISO Language Code. These codes are the lower-case, two-letter codes as defined by ISO-639. You can find a full list of these codes at a number of sites, such as:
http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt

The second argument to both constructors is a valid ISO Country Code. These codes are the upper-case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as:
http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html

The second constructor requires a third argument--the Variant. The Variant codes are vendor and browser-specific. For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. Where there are two variants, separate them with an underscore, and put the most important one first. For example, a Traditional Spanish collation might be referenced, with "ES", "ES", "Traditional_WIN".

The third constructor requires two additional arguments in addition to language, country, and variant: Win32 locale and code page identifiers.

Because a Locale object is just an identifier for a region, no validity check is performed when you construct a Locale. If you want to see whether particular resources are available for the Locale you construct, you must query those resources. For example, ask the NumberFormat for the locales it supports using its getAvailableLocales method.

Note: When you ask for a resource for a particular locale, you get back the best available match, not necessarily precisely what you asked for. For more information, look at ResourceBundle.

The Locale class provides a number of convenient constants that you can use to create Locale objects for commonly used locales. For example, the following creates a Locale object for the United States:


Locale.US

Once you've created a Locale you can query it for information about itself. Use getCountry to get the ISO Country Code and getLanguage to get the ISO Language Code. You can use getDisplayCountry to get the name of the country suitable for displaying to the user. Similarly, you can use getDisplayLanguage to get the name of the language suitable for displaying to the user. Interestingly, the getDisplayXXX methods are themselves locale-sensitive and have two versions: one that uses the default locale and one that uses the locale specified as an argument.

There are a number of classes that perform locale-sensitive operations. For example, the NumberFormat class formats numbers, currency, or percentages in a locale-sensitive manner. Classes such as NumberFormat have a number of convenience methods for creating a default object of that type. For example, the NumberFormat class provides these three convenience methods for creating a default NumberFormat object:


NumberFormat.getInstance()
NumberFormat.getCurrencyInstance()
NumberFormat.getPercentInstance()

These methods have two variants; one with an explicit locale and one without; the latter using the default locale.


NumberFormat.getInstance(myLocale)
NumberFormat.getCurrencyInstance(myLocale)
NumberFormat.getPercentInstance(myLocale)

A Locale is the mechanism for identifying the kind of object (NumberFormat) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves.

Each class that performs locale-sensitive operations allows you to get all the available objects of that type. You can sift through these objects by language, country, or variant, and use the display names to present a menu to the user. For example, you can create a menu of all the collation objects suitable for a given language. Such classes must implement these three class methods:


public static Locale[] getAvailableLocales()
public static String getDisplayName(Locale objectLocale,
                                    Locale displayLocale)
public static final String getDisplayName(Locale objectLocale)
    // getDisplayName will throw MissingResourceException if the locale
    // is not one of the available locales.

Also see ResourceBundle, Format, NumberFormat, Collation

Constructors

Locale

public Locale(String language, String country, String variant);

Construct a locale from language, country, variant.

ParameterDescription
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, String variant, int LCID,
        int codepage);

Construct a Locale from language, country, variant, locale identifier, code page.

ParameterDescription
language Lowercase two-letter ISO-639 code.
country Uppercase two-letter ISO-3166 code.
variant Vendor and browser specific code. See class description.
LCID Win32 locale identifier.
codepage Win32 code page.

Locale

public Locale(String language, String country);

Construct a locale from language, country.

ParameterDescription
language Lowercase two-letter ISO-639 code.
country Uppercase two-letter ISO-3166 code.

Methods

clone

public Object clone();

Creates a clone of locale.

Return Value:

Returns clone of locale.

equals

public boolean equals(Object obj);

Compares two locales for equality.

Return Value:

Returns true if equal; otherwise, false.

getCodePage

public int getCodePage();

Gets the code page of the locale.

Return Value:

Returns Win32 code page identifier for the locale.

Exceptions:

MissingResourceException Throws MissingResourceException if there is no code page associated with the locale.

getCountry

public String getCountry();

Gets the programatic name of country field, an uppercased two-letter ISO-3166 code.

Return Value:

Returns lowercased two-letter ISO-639 code representing country.

See Also: getDisplayCountry

getDefault

public static synchronized Locale getDefault();

Common method of getting the current default Locale. Used for the presentation: menus, dialogs, and so on. Generally set once when your applet or application is initialized, then never reset. (If you do reset the default locale, you probably want to reload your GUI, so that the change is reflected in your interface.)

More advanced programs will allow users to use different locales for different fields, e.g. in a spreadsheet.
Note that the initial setting will match the host system.

getDefaultLocaleList

public Locale[] getDefaultLocaleList();

Gets a list of all predefined Locale constants.

Return Value:

Returns list of predefined Locale constants.

getDisplayCountry

public final String getDisplayCountry();

Retrieves the display country of the locale. If the localized name is not found, returns the ISO code. The default locale determines the language used for display country name

Return Value:

Returns name of country for display to user.

getDisplayCountry

public String getDisplayCountry(Locale inLocale);

Retrieves the localized name of the display country of the locale. If the localized name is not found, it returns the ISO code.

Return Value:

Returns the localized name of the country for display to user.

ParameterDescription
inLocale Specifies the desired user language.

getDisplayLanguage

public final String getDisplayLanguage();

Retrieves the display language of the locale. If the localized name is not found, it returns the ISO code. The desired user language is from the default locale.

Return Value:

Returns name of language for display to user.

getDisplayLanguage

public String getDisplayLanguage(Locale inLocale);

Gets the localized name of the display language of the locale. If the localized name is not found, it returns the ISO codes. For example: "English (UK)", "Deutsche (Germany)".

Return Value:

Returns the localized name of language for display to user.

ParameterDescription
inLocale Specifies the desired user language.

getDisplayName

public final String getDisplayName();

Gets the display of the entire locale to the user. If the localized name is not found, it uses the ISO codes. The default locale is used for the presentation language.

getDisplayName

public String getDisplayName(Locale inLocale);

Gets the display of the entire locale to the user. If the localized name is not found, it uses the ISO codes.

Return Value:

Returns name of locale for display to user.

ParameterDescription
inLocale Specifies the desired user language.

getDisplayVariant

public final String getDisplayVariant();

Gets the display of the variant field to the user. If the localized name is not found, it returns the variant code. The default locale is used for the presentation language.

Return Value:

Returns variant field for display to user.

getDisplayVariant

public String getDisplayVariant(Locale inLocale);

Gets the display of the field to the user. If the localized name is not found, it returns the variant code.

Return Value:

Returns localized variant field for display to user.

ParameterDescription
inLocale Specifies the desired user language.

getISO3Country

public String getISO3Country() throws MissingResourceException;

Gets the three-letter ISO country abbreviation of the locale.

Return Value:

Returns the three-letter ISO country abbreviation of the locale.

Exceptions:

MissingResourceException Throws MissingResourceException if the three-letter language abbreviation is not available for this locale.

getISO3Language

public String getISO3Language() throws MissingResourceException;

Gets the three-letter ISO language abbreviation of the locale.

Return Value:

Returns the three-letter ISO language abbreviation of the locale.

Exceptions:

MissingResourceException Throws MissingResourceException if the three-letter language abbreviation is not available for this locale.

getLanguage

public String getLanguage();

Gets the programatic name of the language field, a lowercased, two-letter ISO-639 code.

Return Value:

Returns lowercased two-letter ISO-639 code representing the language.

See Also: getDisplayLanguage

getLCID

public int getLCID() throws MissingResourceException;

Gets the locale identifier (LCID) as used in Windows.

Return Value:

Returns Win32 locale identifier for the locale.

Exceptions:

MissingResourceException Throws MissingResourceException if there is no LCID associated with the locale.

getLocaleFromLCID

public static Locale getLocaleFromLCID(int lcid);

Gets a Locale from the specified locale identifier (LCID).

Return Value:

Returns the Locale if successful; otherwise, returns null.

ParameterDescription
lcid Win32 locale identifier (LCID)

getVariant

public String getVariant();

Gets the programatic name of the variant field.

Return Value:

Returns the programatic name of the variant field.

See Also: getDisplayVariant

hashCode

public synchronized int hashCode();

Overrides hashCode. Since locales are often used in hashtables, it caches the value for speed.

Return Value:

Returns hash code.

setDefault

public static synchronized void setDefault(Locale newLocale);

Sets the default. Normally it is set once at the beginning of an applet or application, then never reset. setDefault does not reset the host locale.

ParameterDescription
newLocale Locale to set to.

toString

public final String toString();

Gets the programatic name of the entire locale with the language, country and variant separated by underscores. If a field is missing, at most one underscore will occur. For example: "EN", "DE_DE", "EN_US_WIN", "DE_POSIX", "FR_MAC".

Return Value:

Returns the programatic name of the locale.

See Also: getDisplayName

Fields

AFRIKAANS
Useful constant for language.
ALBANIAN
Useful constant for language.
AUSTRALIA
Useful constant for country.
BASQUE
Useful constant for language.
BELGIAN
Useful constant for language.
BELGIAN_FRENCH
Useful constant for country.
BRAZILIAN
Useful constant for language.
BULGARIAN
Useful constant for language.
BYELORUS
Useful constant for language.
CANADA
Useful constant for country.
CANADA_FRENCH
Useful constant for country.
CATALAN
Useful constant for language.
CHINA
Useful constant for country.
CHINESE
Useful constant for language.
CROATIAN
Useful constant for language.
CZECH
Useful constant for language.
DANISH
Useful constant for language.
DUTCH
Useful constant for language.
ENGLISH
Useful constant for language.
ESTONIAN
Useful constant for country.
FINNISH
Useful constant for country.
FRANCE
Useful constant for country.
FRENCH
Useful constant for language.
GERMAN
Useful constant for language.
GERMAN_AUSTRIAN
Useful constant for language.
GERMAN_SWISS
Useful constant for language.
GERMANY
Useful constant for country.
GREEK
Useful constant for language.
HEBREW
Useful constant for language.
HUNGARIAN
Useful constant for language.
ICELANDIC
Useful constant for language.
INDONESIAN
Useful constant for language.
IRELAND
Useful constant for country.
ITALIAN
Useful constant for language.
ITALY
Useful constant for country.
JAPAN
Useful constant for country.
JAPANESE
Useful constant for language.
JAPANESE_VERTICAL
Useful constant for language.
KOREA
Useful constant for country.
KOREAN
Useful constant for language.
KOREAN_VERTICAL
Useful constant for language.
LATVIAN
Useful constant for language.
LITHUANIAN
Useful constant for language.
MEXICAN
Useful constant for language.
NEWZEALAND
Useful constant for country.
NORWEGIAN
Useful constant for language.
NORWEGIAN_NYNORSK
Useful constant for language.
POLISH
Useful constant for language.
PORTUGESE
Useful constant for language.
PRC
Useful constant for country.
ROMANIAN
Useful constant for language.
RUSSIAN
Useful constant for language.
SERBIAN
Useful constant for language.
SIMPLIFIED_CHINESE
Useful constant for language.
SIMPLIFIED_CHINESE_VERTICAL
Useful constant for language.
SINGAPORE
Useful constant for language.
SLOVAKIAN
Useful constant for language.
SLOVENIAN
Useful constant for language.
SOUTH_AFRICA
Useful constant for country.
SPANISH
Useful constant for language.
SPANISH_MODERN
Useful constant for language.
SWEDISH
Useful constant for language.
SWISS
Useful constant for country.
TAIWAN
Useful constant for country.
THAI
Useful constant for language.
TRADITIONAL_CHINESE
Useful constant for language.
TRADITIONAL_CHINESE_VERTICAL
Useful constant for language.
TURKISH
Useful constant for language.
UK
Useful constant for country.
UKRANIAN
Useful constant for language.
US
Useful constant for country.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.