简体   繁体   English

gettext的区域设置“转换失败”

[英]Boost locale “Conversion failed” for gettext

When I'm running this example code from boost 当我从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;
}

I'm getting such exception: std::runtime_error("Conversion failed") 我得到这样的异常: std::runtime_error("Conversion failed")

Problem only occurs when I use non ascii chars in translations. 只有在翻译中使用非ascii字符时才会出现问题。

Example content from my .mo file (command: msgunfmt foo.mo ) 我的.mo文件中的示例内容(命令: msgunfmt foo.mo

msgid "Hello World"
msgstr "ąę"

Boost is throwing this exception why try to convert translation. Boost抛出这个异常为什么试图转换翻译。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM