A message has one text per language. At run time the generated code takes a locale and picks one:
| Artefact | Locale |
|---|---|
| string, syslog | the loc argument; without it, the global locale |
| error | the loc argument; without it, std::cerr's |
| streamable | the locale of the stream it is written to |
| exception | the loc given to the constructor; without it, the global locale at construction |
Matching
The locale's name (std::locale::name()) is compared with each language:
- a language matches a locale name that equals it, or that starts with it followed by
_,.or@—[tr]and[tr_TR]both matchtr_TR.UTF-8,[C]matchesC.utf8; - the longer (more specific) language is tried first, so
[tr_TR]wins over[tr]fortr_TR.UTF-8; - if none matches, the message's default language text is used — or its first text if it has none in that language.
A message with a single text has no selection at all: that text is always used and no locale name is looked at.
Practical notes
std::locale( "tr_TR.UTF-8" )throws when the locale is not installed. Catch it and fall back, as the hello example does.- A program's global locale is
Cuntil it callsstd::locale::global(…), so without a locale argument it gets the default text. - The locale also formats the numbers (
1.5vs1,5): passing a locale changes more than the language.

