簡體   English   中英

gettext的區域設置“轉換失敗”

[英]Boost locale “Conversion failed” for gettext

當我從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拋出這個異常為什么試圖轉換翻譯。

要解決這個問題,只需將生成更改為: locale::global(gen("pl_PL.UTF-8"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM