Texts per language

$LANGUAGE en
$MESSAGE Inbox
@ count int
"You have {$count} new messages."
[tr]
"{$count} yeni mesajınız var."
[de]
"Sie haben {$count} neue Nachrichten."

Text lines before any header are in the $LANGUAGE; a [tr] header starts the Turkish text. Each language may put the parameters wherever its grammar wants them.

Which text is used

The generated code reads the name of a locale and matches it against the languages:

  • [tr] matches tr, tr_TR, tr_TR.UTF-8, tr_TR@euro;
  • a more specific [tr_TR] is tried before [tr];
  • nothing matches → the $LANGUAGE text.

Passing the locale

std::locale const tr( "tr_TR.UTF-8" );

InboxStr( 3, tr );                  // a string function — explicit locale
InboxStr( 3 );                      // … or the global locale

std::cout.imbue( tr );
std::cout << InboxStreamable( 3 );  // a streamable — the stream's locale

ThrowInbox( 3, tr );                // the exception keeps the locale

Three things to know:

  1. std::locale( "tr_TR.UTF-8" ) throws if the system does not have that locale. On a minimal container that is common — catch std::runtime_error and fall back.
  2. The global locale is C unless the program calls std::locale::global( std::locale( "" ) ), which takes the user's LANG / LC_ALL.
  3. The locale formats numbers too. {$size} with de_DE writes 1,5; if you want only the language, pass the language's locale and format numbers explicitly.

One language only

A module with a single language has no selection code at all. The std::locale overloads still exist (they control number formatting); drop them with LOCALE EXTRA DISABLE if you do not need them.