📄 locale.java
字号:
/* * @(#)Locale.java 1.69 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved * * The original version of this source code and documentation * is copyrighted and owned by Taligent, Inc., a wholly-owned * subsidiary of IBM. These materials are provided under terms * of a License Agreement between Taligent and Sun. This technology * is protected by multiple US and International patents. * * This notice and attribution to Taligent may not be removed. * Taligent is a registered trademark of Taligent, Inc. * */package java.util;import java.io.*;import java.security.AccessController;import java.text.MessageFormat;import sun.security.action.GetPropertyAction;import sun.text.resources.LocaleData;/** * * A <code>Locale</code> object represents a specific geographical, political, * or cultural region. An operation that requires a <code>Locale</code> to perform * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code> * 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. * * <P> * Create a <code>Locale</code> object using the constructors in this class: * <blockquote> * <pre> * Locale(String language) * Locale(String language, String country) * Locale(String language, String country, String variant) * </pre> * </blockquote> * The language argument is a valid <STRONG>ISO Language Code.</STRONG> * 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: * <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt"> * <code>http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</code></a> * * <P> * The country argument is a valid <STRONG>ISO Country Code.</STRONG> 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: * <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html"> * <code>http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</code></a> * * <P> * The variant argument is a vendor or browser-specific code. * 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 construct a locale with parameters for language, country and variant as: * "es", "ES", "Traditional_WIN". * * <P> * Because a <code>Locale</code> object is just an identifier for a region, * no validity check is performed when you construct a <code>Locale</code>. * If you want to see whether particular resources are available for the * <code>Locale</code> you construct, you must query those resources. For * example, ask the <code>NumberFormat</code> for the locales it supports * using its <code>getAvailableLocales</code> method. * <BR><STRONG>Note:</STRONG> 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 * {@link ResourceBundle}. * * <P> * The <code>Locale</code> class provides a number of convenient constants * that you can use to create <code>Locale</code> objects for commonly used * locales. For example, the following creates a <code>Locale</code> object * for the United States: * <blockquote> * <pre> * Locale.US * </pre> * </blockquote> * * <P> * Once you've created a <code>Locale</code> you can query it for information about * itself. Use <code>getCountry</code> to get the ISO Country Code and * <code>getLanguage</code> to get the ISO Language Code. You can * use <code>getDisplayCountry</code> to get the * name of the country suitable for displaying to the user. Similarly, * you can use <code>getDisplayLanguage</code> to get the name of * the language suitable for displaying to the user. Interestingly, * the <code>getDisplayXXX</code> 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. * * <P> * The Java 2 platform provides a number of classes that perform locale-sensitive * operations. For example, the <code>NumberFormat</code> class formats * numbers, currency, or percentages in a locale-sensitive manner. Classes * such as <code>NumberFormat</code> have a number of convenience methods * for creating a default object of that type. For example, the * <code>NumberFormat</code> class provides these three convenience methods * for creating a default <code>NumberFormat</code> object: * <blockquote> * <pre> * NumberFormat.getInstance() * NumberFormat.getCurrencyInstance() * NumberFormat.getPercentInstance() * </pre> * </blockquote> * These methods have two variants; one with an explicit locale * and one without; the latter using the default locale. * <blockquote> * <pre> * NumberFormat.getInstance(myLocale) * NumberFormat.getCurrencyInstance(myLocale) * NumberFormat.getPercentInstance(myLocale) * </pre> * </blockquote> * A <code>Locale</code> is the mechanism for identifying the kind of object * (<code>NumberFormat</code>) that you would like to get. The locale is * <STRONG>just</STRONG> a mechanism for identifying objects, * <STRONG>not</STRONG> a container for the objects themselves. * * <P> * 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: * <blockquote> * <pre> * 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. * </pre> * </blockquote> * * @see ResourceBundle * @see java.text.Format * @see java.text.NumberFormat * @see java.text.Collator * @version 1.69, 01/23/03 * @author Mark Davis * @since 1.1 */public final class Locale implements Cloneable, Serializable { /** Useful constant for language. */ static public final Locale ENGLISH = new Locale("en","",""); /** Useful constant for language. */ static public final Locale FRENCH = new Locale("fr","",""); /** Useful constant for language. */ static public final Locale GERMAN = new Locale("de","",""); /** Useful constant for language. */ static public final Locale ITALIAN = new Locale("it","",""); /** Useful constant for language. */ static public final Locale JAPANESE = new Locale("ja","",""); /** Useful constant for language. */ static public final Locale KOREAN = new Locale("ko","",""); /** Useful constant for language. */ static public final Locale CHINESE = new Locale("zh","",""); /** Useful constant for language. */ static public final Locale SIMPLIFIED_CHINESE = new Locale("zh","CN",""); /** Useful constant for language. */ static public final Locale TRADITIONAL_CHINESE = new Locale("zh","TW",""); /** Useful constant for country. */ static public final Locale FRANCE = new Locale("fr","FR",""); /** Useful constant for country. */ static public final Locale GERMANY = new Locale("de","DE",""); /** Useful constant for country. */ static public final Locale ITALY = new Locale("it","IT",""); /** Useful constant for country. */ static public final Locale JAPAN = new Locale("ja","JP",""); /** Useful constant for country. */ static public final Locale KOREA = new Locale("ko","KR",""); /** Useful constant for country. */ static public final Locale CHINA = new Locale("zh","CN",""); /** Useful constant for country. */ static public final Locale PRC = new Locale("zh","CN",""); /** Useful constant for country. */ static public final Locale TAIWAN = new Locale("zh","TW",""); /** Useful constant for country. */ static public final Locale UK = new Locale("en","GB",""); /** Useful constant for country. */ static public final Locale US = new Locale("en","US",""); /** Useful constant for country. */ static public final Locale CANADA = new Locale("en","CA",""); /** Useful constant for country. */ static public final Locale CANADA_FRENCH = new Locale("fr","CA",""); /** serialization ID */ static final long serialVersionUID = 9149081749638150636L; /** * 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. * @param language lowercase two-letter ISO-639 code. * @param country uppercase two-letter ISO-3166 code. * @param variant vendor and browser specific code. See class description. * @exception NullPointerException thrown if any argument is null. */ public Locale(String language, String country, String variant) { this.language = convertOldISOCodes(language); this.country = toUpperCase(country).intern(); this.variant = variant.intern(); } /** * 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. * @param language lowercase two-letter ISO-639 code. * @param country uppercase two-letter ISO-3166 code. * @exception NullPointerException thrown if either argument is null. */ public Locale(String language, String country) { this(language, country, ""); } /** * 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. * @param language lowercase two-letter ISO-639 code. * @exception NullPointerException thrown if argument is null. * @since 1.4 */ public Locale(String language) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -