// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ****************************************************************************** * * Copyright (C) 1996-2015, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** * * File locid.h * * Created by: Helena Shih * * Modification History: * * Date Name Description * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to * get and set it. * 04/02/97 aliu Made operator!= inline; fixed return value of getName(). * 04/15/97 aliu Cleanup for AIX/Win32. * 04/24/97 aliu Numerous changes per code review. * 08/18/98 stephen Added tokenizeString(),changed getDisplayName() * 09/08/98 stephen Moved definition of kEmptyString for Mac Port * 11/09/99 weiv Added const char * getName() const; * 04/12/00 srl removing unicodestring api's and cached hash code * 08/10/01 grhoten Change the static Locales to accessor functions ****************************************************************************** */ #ifndef LOCID_H #define LOCID_H #include "unicode/utypes.h" #if U_SHOW_CPLUSPLUS_API #include "unicode/bytestream.h" #include "unicode/localpointer.h" #include "unicode/strenum.h" #include "unicode/stringpiece.h" #include "unicode/uobject.h" #include "unicode/putil.h" #include "unicode/uloc.h" /** * \file * \brief C++ API: Locale ID object. */ U_NAMESPACE_BEGIN // Forward Declarations void U_CALLCONV locale_available_init(); /**< @internal */ class StringEnumeration; class UnicodeString; /** * 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. * * The Locale class is not suitable for subclassing. * * <P> * You can create a <code>Locale</code> object using the constructor in * this class: * \htmlonly<blockquote>\endhtmlonly * <pre> * Locale( const char* language, * const char* country, * const char* variant); * </pre> * \htmlonly</blockquote>\endhtmlonly * The first argument to the constructors 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: * <BR><a href ="http://www.loc.gov/standards/iso639-2/"> * http://www.loc.gov/standards/iso639-2/</a> * * <P> * The second argument to the constructors 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.iso.org/iso/en/prods-services/iso3166ma/index.html"> * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a> * * <P> * The third constructor requires a third argument--the <STRONG>Variant.</STRONG> * The Variant codes are vendor and browser-specific. * For example, use REVISED for a language's revised script orthography, 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_POSIX". * * <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 * <code>ResourceBundle</code>. * * <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 refers to a <code>Locale</code> object * for the United States: * \htmlonly<blockquote>\endhtmlonly * <pre> * Locale::getUS() * </pre> * \htmlonly</blockquote>\endhtmlonly * * <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 takes a locale as an argument and displays the name or country in * a language appropriate to that locale. * * <P> * ICU 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: * \htmlonly<blockquote>\endhtmlonly * <pre> * UErrorCode success = U_ZERO_ERROR; * Locale myLocale; * NumberFormat *nf; * * nf = NumberFormat::createInstance( success ); delete nf; * nf = NumberFormat::createCurrencyInstance( success ); delete nf; * nf = NumberFormat::createPercentInstance( success ); delete nf; * </pre> * \htmlonly</blockquote>\endhtmlonly * Each of these methods has two variants; one with an explicit locale * and one without; the latter using the default locale. * \htmlonly<blockquote>\endhtmlonly * <pre> * nf = NumberFormat::createInstance( myLocale, success ); delete nf; * nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf; * nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf; * </pre> * \htmlonly</blockquote>\endhtmlonly * 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 implement these * three class methods: * \htmlonly<blockquote>\endhtmlonly * <pre> * static Locale* getAvailableLocales(int32_t& numLocales) * static UnicodeString& getDisplayName(const Locale& objectLocale, * const Locale& displayLocale, * UnicodeString& displayName) * static UnicodeString& getDisplayName(const Locale& objectLocale, * UnicodeString& displayName) * </pre> * \htmlonly</blockquote>\endhtmlonly * * @stable ICU 2.0 * @see ResourceBundle */ class U_COMMON_API Locale : public UObject { … }; inline bool Locale::operator!=(const Locale& other) const { … } template<typename StringClass> inline StringClass Locale::toLanguageTag(UErrorCode& status) const { … } inline const char * Locale::getCountry() const { … } inline const char * Locale::getLanguage() const { … } inline const char * Locale::getScript() const { … } inline const char * Locale::getVariant() const { … } inline const char * Locale::getName() const { … } template<typename StringClass, typename OutputIterator> inline void Locale::getKeywords(OutputIterator iterator, UErrorCode& status) const { … } template<typename StringClass, typename OutputIterator> inline void Locale::getUnicodeKeywords(OutputIterator iterator, UErrorCode& status) const { … } template<typename StringClass> inline StringClass Locale::getKeywordValue(StringPiece keywordName, UErrorCode& status) const { … } template<typename StringClass> inline StringClass Locale::getUnicodeKeywordValue(StringPiece keywordName, UErrorCode& status) const { … } inline UBool Locale::isBogus() const { … } U_NAMESPACE_END #endif /* U_SHOW_CPLUSPLUS_API */ #endif