Locale
object represents a specific geographical, political, or cultural region.
More...
#include <locid.h>
Inheritance diagram for Locale:
Public Member Functions | |
Locale () | |
Construct a default locale object, a Locale for the default locale ID. | |
Locale (const char *language, const char *country=0, const char *variant=0) | |
Construct a locale from language, country, variant. | |
Locale (const Locale &other) | |
Initializes a Locale object from another Locale object. | |
~Locale () | |
Destructor ICU 2.0. | |
Locale & | operator= (const Locale &other) |
Replaces the entire contents of *this with the specified value. | |
UBool | operator== (const Locale &other) const |
Checks if two locale keys are the same. | |
UBool | operator!= (const Locale &other) const |
Checks if two locale keys are not the same. | |
const char * | getLanguage () const |
Returns the locale's ISO-639 language code. | |
const char * | getCountry () const |
Returns the locale's ISO-3166 country code. | |
const char * | getVariant () const |
Returns the locale's variant code. | |
const char * | getName () const |
Returns the programmatic name of the entire locale, with the language, country and variant separated by underbars. | |
const char * | getISO3Language () const |
returns the locale's three-letter language code, as specified in ISO draft standard ISO-639-2.. | |
const char * | getISO3Country () const |
Fills in "name" with the locale's three-letter ISO-3166 country code. | |
uint32_t | getLCID (void) const |
Returns the Windows LCID value corresponding to this locale. | |
UnicodeString & | getDisplayLanguage (UnicodeString &dispLang) const |
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in the default locale. | |
UnicodeString & | getDisplayLanguage (const Locale &inLocale, UnicodeString &dispLang) const |
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in the locale specified by "inLocale". | |
UnicodeString & | getDisplayCountry (UnicodeString &dispCountry) const |
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display in the default locale. | |
UnicodeString & | getDisplayCountry (const Locale &inLocale, UnicodeString &dispCountry) const |
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display in the locale specified by "inLocale". | |
UnicodeString & | getDisplayVariant (UnicodeString &dispVar) const |
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display in the default locale. | |
UnicodeString & | getDisplayVariant (const Locale &inLocale, UnicodeString &dispVar) const |
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display in the locale specified by "inLocale". | |
UnicodeString & | getDisplayName (UnicodeString &name) const |
Fills in "name" with the name of this locale in a format suitable for user display in the default locale. | |
UnicodeString & | getDisplayName (const Locale &inLocale, UnicodeString &name) const |
Fills in "name" with the name of this locale in a format suitable for user display in the locale specfied by "inLocale". | |
int32_t | hashCode (void) const |
Generates a hash code for the locale. | |
void | setToBogus () |
Sets the locale to bogus A bogus locale represents a non-existing locale associated with services that can be instantiated from non-locale data in addition to locale (for example, collation can be instantiated from a locale and from a rule set). | |
UBool | isBogus (void) const |
Gets the bogus state. | |
virtual UClassID | getDynamicClassID () const |
ICU "poor man's RTTI", returns a UClassID for the actual class. | |
Static Public Member Functions | |
const Locale & | getEnglish (void) |
Useful constant for this language. | |
const Locale & | getFrench (void) |
Useful constant for this language. | |
const Locale & | getGerman (void) |
Useful constant for this language. | |
const Locale & | getItalian (void) |
Useful constant for this language. | |
const Locale & | getJapanese (void) |
Useful constant for this language. | |
const Locale & | getKorean (void) |
Useful constant for this language. | |
const Locale & | getChinese (void) |
Useful constant for this language. | |
const Locale & | getSimplifiedChinese (void) |
Useful constant for this language. | |
const Locale & | getTraditionalChinese (void) |
Useful constant for this language. | |
const Locale & | getFrance (void) |
Useful constant for this country/region. | |
const Locale & | getGermany (void) |
Useful constant for this country/region. | |
const Locale & | getItaly (void) |
Useful constant for this country/region. | |
const Locale & | getJapan (void) |
Useful constant for this country/region. | |
const Locale & | getKorea (void) |
Useful constant for this country/region. | |
const Locale & | getChina (void) |
Useful constant for this country/region. | |
const Locale & | getPRC (void) |
Useful constant for this country/region. | |
const Locale & | getTaiwan (void) |
Useful constant for this country/region. | |
const Locale & | getUK (void) |
Useful constant for this country/region. | |
const Locale & | getUS (void) |
Useful constant for this country/region. | |
const Locale & | getCanada (void) |
Useful constant for this country/region. | |
const Locale & | getCanadaFrench (void) |
Useful constant for this country/region. | |
const Locale & | getDefault (void) |
Common methods of getting the current default Locale. | |
void | setDefault (const Locale &newLocale, UErrorCode &success) |
Sets the default. | |
Locale | createFromName (const char *name) |
Creates a locale which has had minimal canonicalization as per uloc_getName(). | |
const Locale * | getAvailableLocales (int32_t &count) |
Returns a list of all installed locales. | |
const char *const * | getISOCountries () |
Gets a list of all available 2-letter country codes defined in ISO 639. | |
const char *const * | getISOLanguages () |
Gets a list of all available language codes defined in ISO 639. | |
UClassID | getStaticClassID () |
ICU "poor man's RTTI", returns a UClassID for this class. | |
Protected Member Functions | |
void | setFromPOSIXID (const char *posixID) |
Set this from a single POSIX style locale string. | |
Friends | |
void | locale_set_default_internal (const char *) |
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.
The Locale class is not suitable for subclassing.
You create a Locale
object using the constructor in this class:
. Locale( const char* language, . const char* country, . const char* variant);The first argument to the 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:
<a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt"> http://www.ics.uci.edu/pub/ietf/http/related/iso639.txtThe second argument to the 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.htmlThe third 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".
Because a
Locale
object is just an identifier for a region, no validity check is performed when you construct aLocale
. If you want to see whether particular resources are available for theLocale
you construct, you must query those resources. For example, ask theNumberFormat
for the locales it supports using itsgetAvailableLocales
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 atResourceBundle
.The
Locale
class provides a number of convenient constants that you can use to createLocale
objects for commonly used locales. For example, the following refers to aLocale
object for the United States:Once you've created a
Locale
you can query it for information about itself. UsegetCountry
to get the ISO Country Code andgetLanguage
to get the ISO Language Code. You can usegetDisplayCountry
to get the name of the country suitable for displaying to the user. Similarly, you can usegetDisplayLanguage
to get the name of the language suitable for displaying to the user. Interestingly, thegetDisplayXXX
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.The TIFC provides 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 asNumberFormat
have a number of convenience methods for creating a default object of that type. For example, theNumberFormat
class provides these three convenience methods for creating a defaultNumberFormat
object: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;Each of these methods has two variants; one with an explicit locale and one without; the latter using the default locale.nf = NumberFormat::createInstance( myLocale, success ); delete nf; nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf; nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf;ALocale
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 implement these three class methods:
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)ICU 2.0
|
Construct a default locale object, a Locale for the default locale ID.
|
|
Construct a locale from language, country, variant. If an error occurs, then the constructed object will be "bogus" (isBogus() will return TRUE).
|
|
Initializes a Locale object from another Locale object.
|
|
Creates a locale which has had minimal canonicalization as per uloc_getName().
|
|
Returns a list of all installed locales.
|
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this language. ICU 2.0 |
|
Returns the locale's ISO-3166 country code.
|
|
Common methods of getting the current default Locale. Used for the presentation: menus, dialogs, etc. 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.
|
|
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display in the locale specified by "inLocale". For example, if the locale's country code is "US" and inLocale's language code is "fr", this function would set dispCountry to "Etats-Unis".
|
|
Fills in "dispCountry" with the name of this locale's country in a format suitable for user display in the default locale. For example, if the locale's country code is "FR" and the default locale's language code is "en", this function would set dispCountry to "France".
|
|
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in the locale specified by "inLocale". For example, if the locale's language code is "en" and inLocale's language code is "fr", this function would set dispLang to "Anglais".
|
|
Fills in "dispLang" with the name of this locale's language in a format suitable for user display in the default locale. For example, if the locale's language code is "fr" and the default locale's language code is "en", this function would set dispLang to "French".
|
|
Fills in "name" with the name of this locale in a format suitable for user display in the locale specfied by "inLocale". This function uses getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display name in the format "language (country[,variant])". For example, if inLocale is fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's display name would be "norvégien (Norvège,NY)".
|
|
Fills in "name" with the name of this locale in a format suitable for user display in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display name in the format "language (country[,variant])". For example, if the default locale is en_US, then fr_FR's display name would be "French (France)", and es_MX_Traditional's display name would be "Spanish (Mexico,Traditional)".
|
|
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display in the locale specified by "inLocale".
|
|
Fills in "dispVar" with the name of this locale's variant code in a format suitable for user display in the default locale.
|
|
ICU "poor man's RTTI", returns a UClassID for the actual class. ICU 2.2 Implements UObject. |
|
Useful constant for this language. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this language. ICU 2.0 |
|
Useful constant for this language. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Fills in "name" with the locale's three-letter ISO-3166 country code.
|
|
returns the locale's three-letter language code, as specified in ISO draft standard ISO-639-2..
|
|
Gets a list of all available 2-letter country codes defined in ISO 639. This is a pointer to an array of pointers to arrays of char. All of these pointers are owned by ICU-- do not delete them, and do not write through them. The array is terminated with a null pointer.
|
|
Gets a list of all available language codes defined in ISO 639. This is a pointer to an array of pointers to arrays of char. All of these pointers are owned by ICU-- do not delete them, and do not write through them. The array is terminated with a null pointer.
|
|
Useful constant for this language. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this language. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this language. ICU 2.0 |
|
Returns the locale's ISO-639 language code.
|
|
Returns the Windows LCID value corresponding to this locale. This value is stored in the resource data for the locale as a one-to-four-digit hexadecimal number. If the resource is missing, in the wrong format, or there is no Windows LCID value that corresponds to this locale, returns 0. ICU 2.0 |
|
Returns the programmatic name of the entire locale, with the language, country and variant separated by underbars. If a field is missing, up to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN", "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
|
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this language. ICU 2.0 |
|
ICU "poor man's RTTI", returns a UClassID for this class. ICU 2.2 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this language. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Useful constant for this country/region. ICU 2.0 |
|
Returns the locale's variant code.
|
|
Generates a hash code for the locale. ICU 2.0 |
|
Gets the bogus state. Locale object can be bogus if it doesn't exist
|
|
Checks if two locale keys are not the same.
|
|
Replaces the entire contents of *this with the specified value.
|
|
Checks if two locale keys are the same.
|
|
Sets the default. Normally set once at the beginning of a process, then never reset. setDefault() only changes ICU's default locale ID, not the default locale ID of the runtime environment.
|
|
Set this from a single POSIX style locale string.
For internal use only.
|
|
Sets the locale to bogus A bogus locale represents a non-existing locale associated with services that can be instantiated from non-locale data in addition to locale (for example, collation can be instantiated from a locale and from a rule set). ICU 2.1 |