Chapter 17. Locale objects

Index

Character type functions using input or output streams
Wide/narrow character conversion
Wide/narrow character conversion using input iterators
Wide/narrow character conversion using output iterators
Message catalogs
gettextmsg()
Single and plural forms

This is a reference-counted wrapper for the C++ library's localization library:

#include <x/locale.H>

x::locale myLocale;

x::locale is a reference to a reference-counted object that represents a C++ library locale. The default constructor creates a locale object for the current global application locale.

x::locale myLocale(x::locale::create("en_US.utf-8"));

This example creates a reference to an object for an explicitly named locale.

x::locale myLocale(x::locale::create(""));

An empty locale name creates a locale object for the locale specified by the environment variables. x::const_locale is a reference to a constant locale object, that cannot be modified. At present, no methods are defined for modifying an existing locale object, at this time x::locale is converted to x::const_locale without any loss of functionality (but not the other way around, of course).

std::cout << myLocale->name() << std::endl;

name() returns the locale's name.

myLocale->global();

global() sets the given locale as the applications global locale.

auto locale=x::locale::base::global();

This returns an object representing whatever the current global application locale is.

auto locale=x::locale::base::utf8();

This is a convenience function that returns the en_US.UTF-8 locale. This is equivalent to invoking x::locale::create("en_US.UTF-8")

auto locale=x::locale::base::environment();

This is a convenience function that returns the system environment locale. This is equivalent to invoking x::locale::create("")

myLocale->imbue(std::cout);

imbue() invokes the imbue() method of the given C++ library object, to imbue the object with the referenced locale.

Note

See Appendix A, Porting and compatibility notes regarding portability notes that affect x::locale.

Character type functions using input or output streams

#include <x/locale.H>
#include <x/ctype.H>
	  
x::ctype ct(myLocale);

x::ctype is a reference to a reference-counted object that implements character conversion and classification functions, such as converting strings to uppercase or lowercase. The conversion takes place in the locale specified by the locale object passed to x::ctype's constructor. x::wctype is the wide character version.