std::locale::messages
viene utilizzato per aprire cataloghi di messaggi (più comunemente GNU gettext
) comprese stringhe tradotte. Ecco un example che si apre un catalogo messaggio esistente utilizzando su Linux (per sed
) in tedesco, recupera (utilizzando get()
) ed emette le traduzioni per le stringhe inglesi:
#include <iostream>
#include <locale>
int main()
{
std::locale loc("de_DE.utf8");
std::cout.imbue(loc);
auto& facet = std::use_facet<std::messages<char>>(loc);
auto cat = facet.open("sed", loc);
if(cat < 0)
std::cout << "Could not open german \"sed\" message catalog\n";
else
std::cout << "\"No match\" in German: "
<< facet.get(cat, 0, 0, "No match") << '\n'
<< "\"Memory exhausted\" in German: "
<< facet.get(cat, 0, 0, "Memory exhausted") << '\n';
facet.close(cat);
}
quali uscite:
"No match" in German: Keine Übereinstimmung
"Memory exhausted" in German: Speicher erschöpft
Modifica: chiarimento in base a this comment.
Non solo GNU gettext. I cataloghi di messaggi fanno parte di POSIX (ad es. Gencat (1), catopen (3)). Windows ha anche cataloghi di messaggi, anche se non sono sicuro se si siano mai presi la briga di implementare le faccette dei messaggi di impostazioni internazionali standard. – bames53