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.