Reputation: 93
This might be a simple question but I'm struggling with it for quite a time, that's why I hope that one of you may help me.
I'm trying to get Boost locale's function translate
to work. Referring this example code:
#include <boost/locale.hpp>
#include <iostream>
using namespace std;
using namespace boost::locale;
int main()
{
generator gen;
// Specify location of dictionaries
gen.add_messages_path(".");
gen.add_messages_domain("hello");
// Generate locales and imbue them to iostream
locale::global(gen(""));
cout.imbue(locale());
// Display a message using current system locale
cout << translate("Hello World") << endl;
}
Let's say I want to translate into german. Do I have to pass "de"
like locale::global(gen("de"));
?
I read something of *.po
and *.mo
files.
Can someone explain me how this all works?
Thanks in advance.
Upvotes: 2
Views: 992
Reputation: 183
Each locale is defined by a specific locale identifier, which contains a mandatory part (Language) and several optional parts (Country, Variant, keywords and character encoding of std::string). Boost.Locale uses the POSIX naming convention for locales, i.e. a locale is defined as language[_COUNTRY][.encoding][@variant], where lang is ISO-639 language name like "en" or "ru", COUNTRY is the ISO-3166 country identifier like "US" or "DE", encoding is the eight-bit character encoding like UTF-8 or ISO-8859-1, and variant is additional options for specializing the locale, like euro or calendar=hebrew, see Variant. Note that each locale should include the encoding in order to handle char based strings correctly. https://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/locale_gen.html
In your case it could be locale::global(gen("de_DE.UTF-8"));
I would recommend you these sources for further information:
Upvotes: 2