Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Internationalization Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

10.3 Locale Objects

In the Internationalization Module, class RWULocale represents a locale. Services in the Internationalization Module that are sensitive to the locale of the user accept an RWULocale to tailor the behavior of the service.

RWULocale does not directly map to RWLocale in the Essential Tools Module of SourcePro Core, the POSIX locale, or std::locale. As described in Section 10.2, RWULocale clearly defines the language, country, and variant codes, unlike the less clearly specified names allowed by these other representations. RWULocale does not directly provide formatting services, as in the SourcePro and Standard C++ locale classes. Instead, RWULocale is used to index into the rich set of services provided by the Internationalization Module. For example, an RWULocale instance may be used to retrieve locale-dependent data from an RWUResourceBundle (see Section 10.4), or to take language-specific conventions into account when collating strings using RWUCollator (see Chapter 6).

10.3.1 Creating Locales

You can construct an RWULocale instance from a character string describing the full name of the locale, including language, country, and variant codes. (See Section 10.2.) For example:

Alternatively, you can construct an RWULocale from separate language, country, and variant character strings. Use a null pointer to indicate an absent part. The default variant is the empty string. For example:

10.3.2 Using Locales

Services in the Internationalization Module that are sensitive to the locale of the user of a program accept an RWULocale to tailor the behavior of the service. For example, an RWULocale instance may be used to take language-specific conventions into account when collating strings using RWUCollator (see Chapter 6):

Because an RWULocale provides nothing more than simple locale identification, no validity checking is performed when you create an RWULocale. To check for valid locale names, use RWUAvailableLocaleList to construct an iterator that provides access to the list of locale names recognized by the Internationalization Module, as described in Section 10.2.3.

Because construction of an RWULocale is cheap, you cannot modify an RWULocale instance once it is created. However, accessor methods are provided. For example, getName() returns the full name of a locale as an RWCString. Similarly, getLanguage(), getCountry(), and getVariant() return the separate language, country, and variant components of a locale.

Methods are also provided for accessing the identifiers of a locale in a form suitable for displaying to an end user in a locale-sensitive manner. For example, getDisplayName() returns the full name of a locale as an RWUString according to the default locale. You can also pass in another locale indicating the locale of the end user. For example, this code returns the full name of a locale according to the Germany locale:

Similarly, getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() return the separate language, country, and variant components of a locale name according to a given locale.

10.3.3 The Default Locale

The current default locale is set at startup time to some system-specific value. On Windows, for example, the system default locale is set at installation, but can be changed in the Control Panel. On POSIX systems, the environment variable LANG and the LC_* variables are used to specify the default locale.

The static method RWULocale::getDefault() returns the default RWULocale for the executable. Methods in the Internationalization Module that take an RWULocale to tailor their behavior to a specific locale use the locale returned by RWULocale:getDefault() as the default value if no locale is specified.

You can change the default locale at run time using the static method RWULocale::setDefault(). For example:



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.