A message has one text per language. At run time the generated code takes a locale and picks one:

ArtefactLocale
string, syslogthe loc argument; without it, the global locale
errorthe loc argument; without it, std::cerr's
streamablethe locale of the stream it is written to
exceptionthe 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 match tr_TR.UTF-8, [C] matches C.utf8;
  • the longer (more specific) language is tried first, so [tr_TR] wins over [tr] for tr_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 C until it calls std::locale::global(…), so without a locale argument it gets the default text.
  • The locale also formats the numbers (1.5 vs 1,5): passing a locale changes more than the language.