这可能是一个简单的问题,但我已经为此苦苦挣扎了很长一段时间,这就是为什么我希望你们中的一个人可以帮助我。
我正在尝试让 Boost locale 的函数 translate
正常工作。引用此示例代码:
#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;
}
假设我想翻译成德语。我是否必须像
locale::global(gen("de"));
一样传递"de"
?我读了一些
*.po
和*.mo
文件。 有人可以解释一下这一切是如何运作的吗?
提前致谢。
最佳答案
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
在您的情况下,它可能是 locale::global(gen("de_DE.UTF-8"));
我会向您推荐这些来源以获取更多信息:
关于c++ - Boost Locale 翻译入门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70381091/