|
Boost Users : |
Subject: [Boost-users] Boost 1.49 Locale Conversion failed
From: NtVisigoth (ntvisigoth_at_[hidden])
Date: 2012-07-10 05:36:32
Hello, everyone!
I have already answred here:
http://lists.boost.org/boost-users/2012/07/75097.php
But previous latter badly typed.
When using boost::locale with the russian language of the string in UTF-8
encoding I get an error while getting the locale.
An exception with the message e.what(): "Conversion failed" is thrown
My code is not very different from that in the examples:
#define TR(S) boost::locale::translate(S).str()
const std::string strDefaultLangId( "en" );
int main( int argc, char * argv[] )
{
using namespace std;
using namespace boost::locale;
int exitCode = EXIT_SUCCESS;
try
{
generator gen;
gen.add_messages_path("g:\\source\\boost_locale\\languages\\");
gen.add_messages_domain("messages");
std::string language( argc == 2 ? argv[1] :
strDefaultLangId.c_str() );
std::locale loc = gen( language );
locale::global( loc );
std::wstring s = TR(L"hello world");
wcout << s << endl;
}
catch( exception& e )
{
cout << "Error : " << e.what() << endl;
exitCode = EXIT_FAILURE;
}
catch( ... )
{
cout << "Unknown error" << endl;
exitCode = EXIT_FAILURE;
}
return exitCode;
}
The path to the file with the russian language:
"g:\source\boost_locale\languages\ru\LC_MESSAGES\messages.mo"
What could be wrong?
* Is it necessary to use the backends?
* Is it yet necessary to call imbue on the stream? But I'd like avoid it
because I am going to write the log using glog.
Compillers : Microsoft Visual Studio 2008 and 2010
Boost version : 1.49
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net