c++ - 为 gettext boost 语言环境 "Conversion failed"

标签 c++ boost gettext mo boost-locale

当我运行来自 boost 的示例代码时

#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("foo");
    // Generate locales and imbue them to iostream
    locale::global(gen("pl_PL"));
    cout.imbue(locale());
    // Display a message using current system locale
    cout << translate("Hello World") << endl;
}

我遇到这样的异常:std::runtime_error("Conversion failed")

只有当我在翻译中使用非 ascii 字符时才会出现问题。

我的 .mo 文件中的示例内容(命令:msgunfmt foo.mo)

msgid "Hello World"
msgstr "ąę"

最佳答案

Boost 正在抛出此异常,为什么要尝试转换翻译。

要解决这个问题,只需将 generation 更改为: locale::global(gen("pl_PL.UTF-8"));

关于c++ - 为 gettext boost 语言环境 "Conversion failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51745221/

相关文章:

c++ - 将 python 与 c++ 接口(interface)

c++ - 用于创建结构的可变参数宏

c++ - MSVC UTF8 字符串编码使用不正确的代码点

c++ - 如何确定 boost::variant 变量是否为空?

c++ - BOOST_CHECK_CLOSE 即使两个值低于阈值也会失败

python - 如何在 Windows 上安装 gnu gettext (>0.15)?所以我可以在 Django 中生成 .po/.mo 文件

c++ - mpg123 链接错误 "_read"和 "_lseek"

c++ - 使用带有 qi::grammar 的 boost::spirit::qi::phrase_parse() 时出错

android - 带有 gettext 和 editText 的空指针

localization - 有没有办法确定 .PO 文件的覆盖范围?