|
|
||||||||||||||||||||||||||||||||||||||||||||||
Class Localepublic final class Locale implements Cloneable, Serializable { // Fields static public final Locale CANADA; static public final Locale CANADA_FRENCH; static public final Locale CHINA; static public final Locale CHINESE; static public final Locale ENGLISH; static public final Locale FRANCE; static public final Locale FRENCH; static public final Locale GERMAN; static public final Locale GERMANY; static public final Locale ITALIAN; static public final Locale ITALY; static public final Locale JAPAN; static public final Locale JAPANESE; static public final Locale KOREA; static public final Locale KOREAN; static public final Locale PRC; static public final Locale SIMPLIFIED_CHINESE; static public final Locale TAIWAN; static public final Locale TRADITIONAL_CHINESE; static public final Locale UK; 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 String getCountry(); public static synchronized Locale getDefault(); 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 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: 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: 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. 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. 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 ConstructorsLocalepublic Locale(String language, String country, String variant); Localepublic Locale(String language, String country, String variant, int LCID, int codepage); Localepublic Locale(String language, String country); Methodsclonepublic Object clone(); equalspublic boolean equals(Object obj); getCountrypublic String getCountry(); getDefaultpublic static synchronized Locale getDefault(); getDisplayCountrypublic final String getDisplayCountry(); getDisplayCountrypublic String getDisplayCountry(Locale inLocale); getDisplayLanguagepublic final String getDisplayLanguage(); getDisplayLanguagepublic String getDisplayLanguage(Locale inLocale); getDisplayNamepublic final String getDisplayName(); getDisplayNamepublic String getDisplayName(Locale inLocale); getDisplayVariantpublic final String getDisplayVariant(); getDisplayVariantpublic String getDisplayVariant(Locale inLocale); getISO3Countrypublic String getISO3Country() throws MissingResourceException; getISO3Languagepublic String getISO3Language() throws MissingResourceException; getLanguagepublic String getLanguage(); getVariantpublic String getVariant(); hashCodepublic synchronized int hashCode(); setDefaultpublic static synchronized void setDefault(Locale newLocale); toStringpublic final String toString(); Fields
|
© 1998 Microsoft Corporation. All rights reserved. Terms of use. |