【问题标题】:Boost locale "Conversion failed" for gettext为 gettext 提升语言环境“转换失败”
【发布时间】:2019-01-15 15:10:35
【问题描述】:

当我从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 "ąę"

【问题讨论】:

    标签: c++ boost gettext mo boost-locale


    【解决方案1】:

    Boost 抛出这个异常为什么要转换翻译。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      • 2012-07-18
      • 2014-03-09
      • 2023-04-01
      • 1970-01-01
      • 2023-04-03
      相关资源
      最近更新 更多