Gelldur
Gelldur

Reputation: 11558

Boost locale "Conversion failed" for gettext

When I'm running this example code from 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")

Problem only occurs when I use non ascii chars in translations.

Example content from my .mo file (command: msgunfmt foo.mo)

msgid "Hello World"
msgstr "ąę"

Upvotes: 3

Views: 569

Answers (1)

Gelldur
Gelldur

Reputation: 11558

Boost is throwing this exception why try to convert translation.

To fix that just change generation to: locale::global(gen("pl_PL.UTF-8"));

Upvotes: 3

Related Questions