Internationalization Module User’s Guide : Chapter 10 Locales and Localized Resources : Locale Objects
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 “Named Locales”, 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 “Localized Resources”), or to take language-specific conventions into account when collating strings using RWUCollator (see Chapter 6).
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 “Named Locales”.) For example:
 
RWULocale loc = RWULocale("es_ES_TRADITIONAL");
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:
 
RWULocale loc = RWULocale("en", "US");
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):
 
RWULocale myLocale("zh_TW");
RWUCollator myCollator(myLocale);
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 “Listing Available Locales”.
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:
 
RWULocale loc = RWULocale("en_US");
RWUString str = loc.getDisplayName(RWULocale("de_DE"));
Similarly, getDisplayLanguage(), getDisplayCountry(), and getDisplayVariant() return the separate language, country, and variant components of a locale name according to a given locale.
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:
 
RWULocale loc = RWULocale("en_US");
RWULocale::setDefault(loc);