# Localization library

> C++ Atlas: `cppatlas.com/w/cpp/locale` | Source: https://en.cppreference.com/w/cpp/locale | Domain: Localization | Standards: C++11, C++17, C++26

The locale facility includes internationalization support for character classification and string collation, numeric, monetary, and date/time formatting and parsing, and message retrieval.

## Official Specification Summary (cppreference)

The locale facility includes internationalization support for character classification and string collation, numeric, monetary, and date/time formatting and parsing, and message retrieval. Locale settings control the behavior of stream I/O, regular expression library, and other components of the C++ standard library.

### Locales and facets

Defined in header `<locale>`

**Locales**

- `locale`: set of polymorphic facets that encapsulate cultural differences (class)
- `use_facet`: obtains a facet from a locale (function template)
- `has_facet`: checks if a locale implements a specific facet (function template)

**Facet category base classes**

- `ctype_base`: defines character classification categories (class)
- `codecvt_base`: defines character conversion errors (class)
- `messages_base`: defines messages catalog type (class)
- `time_base`: defines date format constants (class)
- `money_base`: defines monetary formatting patterns (class)

**ctype facets**

- `ctype`: defines character classification tables (class template)
- `ctype_byname`: represents the system-supplied `std::ctype` for the named locale (class template)
- `ctype<char>`: specialization of `std::ctype` for type `char` (class template specialization)
- `codecvt`: converts between character encodings, including UTF-8, UTF-16, UTF-32 (class template)
- `codecvt_byname`: represents the system-supplied `std::codecvt` for the named locale (class template)

**numeric facets**

- `num_get`: parses numeric values from an input character sequence (class template)
- `num_put`: formats numeric values for output as character sequence (class template)
- `numpunct`: defines numeric punctuation rules (class template)
- `numpunct_byname`: represents the system-supplied `std::numpunct` for the named locale (class template)

**collate facets**

- `collate`: defines lexicographical comparison and hashing of strings (class template)
- `collate_byname`: represents the system-supplied `std::collate` for the named locale (class template)

**time facets**

- `time_get`: parses time/date values from an input character sequence into `std::tm` (class template)
- `time_get_byname`: represents the system-supplied `std::time_get` for the named locale (class template)
- `time_put`: formats contents of `std::tm` for output as character sequence (class template)
- `time_put_byname`: represents the system-supplied `std::time_put` for the named locale (class template)

**monetary facets**

- `money_get`: parses and constructs a monetary value from an input character sequence (class template)
- `money_put`: formats a monetary value for output as a character sequence (class template)
- `moneypunct`: defines monetary formatting parameters used by `std::money_get` and `std::money_put` (class template)
- `moneypunct_byname`: represents the system-supplied `std::moneypunct` for the named locale (class template)

**messages facets**

- `messages`: implements retrieval of strings from message catalogs (class template)
- `messages_byname`: represents the system-supplied `std::messages` for the named locale (class template)

### Character classification and conversion

Defined in header `<locale>`

**Character classification**

- `isspace(std::locale)`: checks if a character is classified as whitespace by a locale (function template)
- `isblank(std::locale)` (C++11): checks if a character is classified as a blank character by a locale (function template)
- `iscntrl(std::locale)`: checks if a character is classified as a control character by a locale (function template)
- `isupper(std::locale)`: checks if a character is classified as uppercase by a locale (function template)
- `islower(std::locale)`: checks if a character is classified as lowercase by a locale (function template)
- `isalpha(std::locale)`: checks if a character is classified as alphabetic by a locale (function template)
- `isdigit(std::locale)`: checks if a character is classified as a digit by a locale (function template)
- `ispunct(std::locale)`: checks if a character is classified as punctuation by a locale (function template)
- `isxdigit(std::locale)`: checks if a character is classified as a hexadecimal digit by a locale (function template)
- `isalnum(std::locale)`: checks if a character is classified as alphanumeric by a locale (function template)
- `isprint(std::locale)`: checks if a character is classified as printable by a locale (function template)
- `isgraph(std::locale)`: checks if a character is classified as graphical by a locale (function template)

**Character conversions**

- `toupper(std::locale)`: converts a character to uppercase using the ctype facet of a locale (function template)
- `tolower(std::locale)`: converts a character to lowercase using the `ctype` facet of a locale (function template)

**String and stream conversions**

- `wstring_convert` (C++11): performs conversions between a wide string and a byte string (class template)
- `wbuffer_convert` (C++11): performs conversion between a byte stream buffer and a wide stream buffer (class template)

(until C++26):

### Locale-independent unicode conversion facets

Defined in header `<codecvt>`

- `codecvt_utf8` (C++11): converts between UTF-8 and UCS-2/UCS-4 (class template)
- `codecvt_utf16` (C++11): converts between UTF-16 and UCS-2/UCS-4 (class template)
- `codecvt_utf8_utf16` (C++11): converts between UTF-8 and UTF-16 (class template)
- `codecvt_mode` (C++11): tags to alter behavior of the standard codecvt facets (enum)

### C library locales

Defined in header `<clocale>`

- `setlocale`: gets and sets the current C locale (function)
- `LC_ALL`, `LC_COLLATE`, `LC_CTYPE`, `LC_MONETARY`, `LC_NUMERIC`, `LC_TIME`: locale categories for `std::setlocale` (macro constant)
- `localeconv`: queries numeric and monetary formatting details of the current locale (function)
- `lconv`: formatting details, returned by `std::localeconv` (class)

### See also

- [C documentation for Localization support](https://en.cppreference.com/w/c/locale)

---
Attribution: content from https://en.cppreference.com/w/cpp/locale (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.