java.util.Locale
java.lang.Object
None
java.lang.Cloneable, java.io.Serializable
New as of JDK 1.1
The Locale class is used for internationalization. Instances of Locale specify language and formatting customs by identifying a language and a country. A Locale object may also specify a platform-specific variant. Other classes throughout the JDK use Locale objects to determine how to represent themselves to the user. The tasks performed by these classes are called locale-sensitive tasks; the tasks should be done in a way that conforms with the conventions of a particular country and language.
There are a number of classes provided with Java that have static methods that create instances of locale-specific subclasses. For example, the NumberFormat class contains static methods named getInstance() that create and return locale-specific instances of subclasses of NumberFormat. A particular NumberFormat instance knows how to format numbers, currency values, and percentages appropriately for a particular locale. Note that it is the responsibiity of a class like NumberFormat to implement the logic needed to translate locale-identifying information into actual subclass instances.
Classes like NumberFormat that can create locale-specific instances are expected to follow certain conventions:
public static Locale[] getAvailableLocales()
This requirement is not specified through an interface declaration because interfaces cannot declare static methods. The purpose of this method is to facilitate presenting the user with a list or menu of locale choices. The getAvailableLocales() method should return an array of Locale objects that identifies all of the locales for which the class can create locale-specific instances.
Two additional methods are recommended for helping to display the locale choices:
public static final String getDisplayName(Locale objectLocale) public static String getDisplayName(Locale objectLocale, Locale displayLocale)
The first form of getDisplayName() should return a description of objectLocale that is suitable for display in the default locale. The second form should return a description of objectLocale that is suitable for display in the locale specified by displayLocale. Implementations of these methods generally call the getDisplayName() method of the Locale object.
The language, country and variant information that are encapsulated by a Locale object are specified to a constructor as strings. The language for a Locale should be specified as one of the two-letter lowercase language codes defined by ISO-639. Look for a complete list at http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt.
The country for a Locale object should be specified as either "" to indicate that no country is specified, or as one of the two-letter uppercase country codes defined by ISO-3166. Check the site, http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html, for a complete list
Variant codes are platform-specific.
Although the Locale is constructed from these three types of codes, human-readable names can be obtained by calling getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant().
The Locale class defines a number of constant Locale objects that represent some of the major languages and countries of the world.
public abstract class java.util.Locale extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable { // Constants public final static Locale CANADA; public final static Locale CANADA_FRENCH; public final static Locale CHINA; public final static Locale CHINESE; public final static Locale ENGLISH; public final static Locale FRANCE; public final static Locale FRENCH; public final static Locale GERMAN; public final static Locale GERMANY; public final static Locale ITALIAN; public final static Locale ITALY; public final static Locale JAPAN; public final static Locale JAPANESE; public final static Locale KOREA; public final static Locale KOREAN; public final static Locale PRC; public final static Locale SIMPLIFIED_CHINESE; public final static Locale TAIWAN; public final static Locale TRADITIONAL_CHINESE; public final static Locale UK; public final static Locale US; // Constructors public Locale(String language, String country); public Locale(String language, String country, String variant); // Class Methods public static synchronized Locale getDefault(); public static synchronized void setDefault(Locale newLocale); // Instance Methods public Object clone(); public boolean equals(Object obj); public String getCountry(); 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(); public String getISO3Language(); public String getLanguage(); public String getVariant(); public synchronized int hashCode(); public final String toString(); }
A locale that represents English-speaking Canada.
A locale that represents French-speaking Canada.
A locale that represents China.
A locale that represents the Chinese language.
A locale that represents the English language.
A locale that represents France.
A locale that represents the French language.
A locale that represents the German language.
A locale that represents Germany.
A locale that represents the Italian language.
A locale that represents Italy.
A locale that represents Japan.
A locale that represents the Japanese language.
A locale that represents Korea.
A locale that represents the Korean language.
A locale that represents the People's Republic of China. It is equivalent to CHINA.
A locale that represents the Chinese language as used in mainland China.
A locale that represents Taiwan.
A locale that represents the Chinese language as used in Taiwan.
A locale that represents the United Kingdom.
A locale that represents the United States.
A two-letter ISO-639 language code.
A two-letter ISO-3166 country code or "" to omit the country specification.
This constructor creates a Locale that represents the given language and country.
A two-letter ISO-639 language code.
A two-letter ISO-3166 country code or "" to omit the country specification.
A vendor-specific variant code.
This constructor creates a Locale that represents the given language, country, and variant.
The default Locale.
This method returns the current default Locale. An application or applet uses this method to find out how to present locale-sensitive information, such as textual strings and numbers. The method is generally called during application initialization to get the default Locale. Once the locale is set, it almost never changes. If you do change the locale, you should probably reload the GUI for your application, so that any locale-sensitive information in the interface is changed.
The initial default Locale is set by the host system.
The new default locale.
This method changes the current default locale to newLocale. Note that calling setDefault() does not change the default locale of the host system.
A copy of this Locale.
Object.clone()
This method creates a copy of this Locale and returns it.
The object to be compared with this object.
true if the objects are equal; false if they are not.
Object.equals()
This method returns true if obj is an instance of Locale, and it contains the same value as the object this method is associated with.
The country of this Locale.
This method returns a String that represents the country of this Locale. This String is the same String that was passed to the constructor of this Locale object. The String is normally a two-letter ISO-3166 country code.
The country of this Locale.
This method returns the country of this Locale as a country name in a form appropriate for this Locale. If the country name cannot be found, this method returns the same value as getCountry().
The locale to use when finding the country name.
The country of this Locale, localized to the given locale.
This method returns the country of this Locale as a country name in a form appropriate for inLocale. For example, Locale.ITALY.getDisplayCountry(Locale.GERMAN) returns the German name for Italy, Italien.
The language of this Locale.
This method returns the language of this Locale as a language name in a form appropriate for this Locale. If the language name cannot be found, this method returns the same value as getLanguage().
The locale to use when finding the language name.
The language of this Locale, localized to the given locale.
This method returns the language of this Locale as a language name in a form appropriate for inLocale. For example, Locale.ITALY.getDisplayLanguage(Locale.GERMAN) returns the German name for the Italian language, Italienisch.
A string that represents this Locale.
This method constructs a string that represents this Locale by calling getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant(). In other words, the method returns a string that contains the country name, language name, and variant in a form appropriate for this Locale. If any of the names cannot be found, the String that was passed to the constructor of this Locale object is used instead. These strings are normally two-letter ISO codes.
The locale to use when constructing the string representation.
A string that represents this Locale.
This method constructs a string that represents this Locale by calling getDisplayLanguage(inLocale), getDisplayCountry(inLocale), and getDisplayVariant(inLocale). In other words, the method returns a string that contains the country name, language name, and variant in a form appropriate for inLocale. If any of the names cannot be found, the String that was passed to the constructor of this Locale object is used instead. These strings are normally two-letter ISO codes.
The variant of this Locale.
This method returns the variant of this Locale as a human-readable string in a form appropriate for this Locale. If the variant name cannot be found, this method returns the same value as getVariant().
The locale to use when finding the variant name.
The variant of this Locale, localized to the given locale.
This method returns the variant of this Locale as a human-readable string in a form appropriate for inLocale.
The ISO three-letter country code of this Locale.
If the requested code cannot be found.
This method returns the country of this Locale as a three-letter ISO country code. The country code is obtained from a ResourceBundle for this Locale.
The ISO three-letter language code of this Locale.
If the requested code cannot be found.
This method returns the language of this Locale as a three-letter ISO language code. The language code is obtained from a ResourceBundle for this Locale.
The language of this Locale.
This method returns a String that represents the language of this Locale. This String is the same String that was passed to the constructor of this Locale object. The String is normally a two-letter ISO-639 language code.
The variant of this Locale.
This method returns the variant code of this Locale. If no variant code is specified for this Locale, an empty string is returned.
A hashcode for this Locale.
Object.hashCode()
This method returns a hashcode for this object.
A string representation of this Locale.
Object.toString()
This method returns a string representation of this Locale, constructed from the language code, country code, and variant code. The various codes are separated by underscore characters. If a code is missing, it is omitted.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
finalize() |
Object |
getClass() |
Object |
notify() |
Object |
notifyAll() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Cloneable, DateFormat, NumberFormat, ResourceBundle, Serializable