Boost 1.49 Locale Conversion failed
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
The locale name should be "en_US.UTF-8" or "ru_RU.UTF-8", the default UTF-8 locale is for default system locale "". When you set locale as "en" it assumes that encoding (as not specified) is US-ASCII and conversion fails. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
________________________________ From: NtVisigoth
To: boost-users@lists.boost.org Sent: Tuesday, July 10, 2012 12:36 PM Subject: [Boost-users] Boost 1.49 Locale Conversion failed 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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
2012/7/10 Artyom Beilis
The locale name should be "en_US.UTF-8" or "ru_RU.UTF-8", the default UTF-8 locale is for default system locale "".
When you set locale as "en" it assumes that encoding (as not specified) is US-ASCII and conversion fails.
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
------------------------------ *From:* NtVisigoth
*To:* boost-users@lists.boost.org *Sent:* Tuesday, July 10, 2012 12:36 PM *Subject:* [Boost-users] Boost 1.49 Locale Conversion failed 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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I have : 1) Russian language Filename : g:\project\proba\locale\ru_RU.UTF-8\LC_MESSAGES\messages.mo 2) Russian language locale name in С++-source: const std::string ruLanguage( "ru_RU" ) Is it correct? I dont understand How Boost Locale finds languages MO-file by their locale names in C++-source.
________________________________ From: NtVisigoth
To: boost-users@lists.boost.org Sent: Tuesday, July 10, 2012 4:16 PM Subject: Re: [Boost-users] Boost 1.49 Locale Conversion failed>I have : 1) Russian language Filename : g:\project\proba\locale\ru_RU.UTF-8\LC_MESSAGES\messages.mo 2) Russian language locale name in С++-source: const std::string ruLanguage( "ru_RU" )
Is it correct?
No Filename : g:\project\proba\locale\ru\LC_MESSAGES\messages.mo locale name in С++-source:"ru_RU.UTF-8"
I dont understand How Boost Locale finds languages MO-file by their locale names in C++-source.
See: http://www.boost.org/doc/libs/1_50_0/libs/locale/doc/html/messages_formattin... Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
2012/7/10 Artyom Beilis
________________________________ From: NtVisigoth
To: boost-users@lists.boost.org Sent: Tuesday, July 10, 2012 4:16 PM Subject: Re: [Boost-users] Boost 1.49 Locale Conversion failed>I have : 1) Russian language Filename : g:\project\proba\locale\ru_RU.UTF-8\LC_MESSAGES\messages.mo 2) Russian language locale name in С++-source: const std::string ruLanguage( "ru_RU" )
Is it correct?
No
Filename : g:\project\proba\locale\ru\LC_MESSAGES\messages.mo locale name in С++-source:"ru_RU.UTF-8"
I dont understand How Boost Locale finds languages MO-file by their
locale names in C++-source.
See: http://www.boost.org/doc/libs/1_50_0/libs/locale/doc/html/messages_formattin...
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I written another proba-project: const std::string strLanguagesPath( "g:\\source\\boost_locale\\languages\\" ); const std::string strLanguageFilename( "messages" ); const std::string strEnLanguage( "en_US.UTF-8" ); const std::string strRuLanguage( "ru_RU.UTF-8" ); int main( int argc, char * argv[] ) { using namespace std; using namespace boost::locale; int exitCode = EXIT_SUCCESS; try { generator gen; gen.add_messages_path( strLanguagesPath ); gen.add_messages_domain( strLanguageFilename ); cout << "Start Boost.Locale proba" << endl; std::locale en_loc = gen( strEnLanguage ); wcout << TREX( L"hello world", en_loc ) << endl; std::locale ru_loc = gen( strRuLanguage ); wcout << TREX( L"hello world", ru_loc ) << endl; cout << "Stop Boost.Locale proba" << endl; File paths: g:\source\boost_locale\languages\en\LC_MESSAGES\messages.mo g:\source\boost_locale\languages\ru\LC_MESSAGES\messages.mo and I see in STDOUT following: Start Boost.Locale proba Hello world Localized Stop Boost.Locale proba Press any key to continue . . . There no any russian strings in STDOUT. Why?
On Tue, 10 Jul 2012 16:17:30 +0200, NtVisigoth
I written another proba-project:
const std::string strLanguagesPath( "g:\\source\\boost_locale\\languages\\" ); const std::string strLanguageFilename( "messages" ); const std::string strEnLanguage( "en_US.UTF-8" ); const std::string strRuLanguage( "ru_RU.UTF-8" );
int main( int argc, char * argv[] ) { using namespace std; using namespace boost::locale;
int exitCode = EXIT_SUCCESS; try { generator gen;
gen.add_messages_path( strLanguagesPath ); gen.add_messages_domain( strLanguageFilename );
cout << "Start Boost.Locale proba" << endl; std::locale en_loc = gen( strEnLanguage ); wcout << TREX( L"hello world", en_loc ) << endl;
std::locale ru_loc = gen( strRuLanguage ); wcout << TREX( L"hello world", ru_loc ) << endl; cout << "Stop Boost.Locale proba" << endl;
Hi, I have very little experience with locales, but would note few things here: 1) You're using wcout for UTF-8 - that's not legal, at least in gcc world (have no dev win machine under hand) 2) what's TREX macro? Please always provide full test case. 3) May it be that your console cannot output non-ASCII symbols? Look at the string in debugger just to be sure. -- Slava
2012/7/11
On Tue, 10 Jul 2012 16:17:30 +0200, NtVisigoth
wrote: I written another proba-project:
const std::string strLanguagesPath( "g:\\source\\boost_locale\\**languages\\" ); const std::string strLanguageFilename( "messages" ); const std::string strEnLanguage( "en_US.UTF-8" ); const std::string strRuLanguage( "ru_RU.UTF-8" );
int main( int argc, char * argv[] ) { using namespace std; using namespace boost::locale;
int exitCode = EXIT_SUCCESS; try { generator gen;
gen.add_messages_path( strLanguagesPath ); gen.add_messages_domain( strLanguageFilename );
cout << "Start Boost.Locale proba" << endl; std::locale en_loc = gen( strEnLanguage ); wcout << TREX( L"hello world", en_loc ) << endl;
std::locale ru_loc = gen( strRuLanguage ); wcout << TREX( L"hello world", ru_loc ) << endl; cout << "Stop Boost.Locale proba" << endl;
Hi,
I have very little experience with locales, but would note few things here:
1) You're using wcout for UTF-8 - that's not legal, at least in gcc world (have no dev win machine under hand)
2) what's TREX macro? Please always provide full test case.
3) May it be that your console cannot output non-ASCII symbols? Look at the string in debugger just to be sure.
-- Slava
______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**usershttp://lists.boost.org/mailman/listinfo.cgi/boost-users
2) I am sorry. I use next macroses: #define TR(S) boost::locale::translate(S) #define TREX(S,L) boost::locale::translate(S).str(L) 3) You are right! See: c:\>chcp Active code page: 866
Le 10/07/12 16:17, NtVisigoth a écrit :
2012/7/10 Artyom Beilis
mailto:artyomtnk@yahoo.com> >________________________________ > From: NtVisigoth
mailto:ntvisigoth@gmail.com> >To: boost-users@lists.boost.org mailto:boost-users@lists.boost.org >Sent: Tuesday, July 10, 2012 4:16 PM >Subject: Re: [Boost-users] Boost 1.49 Locale Conversion failed>I have : > >1) Russian language Filename : g:\project\proba\locale\ru_RU.UTF-8\LC_MESSAGES\messages.mo >2) Russian language locale name in ?++-source: >const std::string ruLanguage( "ru_RU" ) > > >Is it correct? No
Filename : g:\project\proba\locale\ru\LC_MESSAGES\messages.mo locale name in ?++-source:"ru_RU.UTF-8"
> > >I dont understand How Boost Locale finds languages MO-file by their locale names in C++-source.
See: http://www.boost.org/doc/libs/1_50_0/libs/locale/doc/html/messages_formattin...
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org mailto:Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I written another proba-project:
const std::string strLanguagesPath( "g:\\source\\boost_locale\\languages\\" ); const std::string strLanguageFilename( "messages" ); const std::string strEnLanguage( "en_US.UTF-8" ); const std::string strRuLanguage( "ru_RU.UTF-8" );
int main( int argc, char * argv[] ) { using namespace std; using namespace boost::locale;
int exitCode = EXIT_SUCCESS; try { generator gen;
gen.add_messages_path( strLanguagesPath ); gen.add_messages_domain( strLanguageFilename );
cout << "Start Boost.Locale proba" << endl; std::locale en_loc = gen( strEnLanguage ); wcout << TREX( L"hello world", en_loc ) << endl;
std::locale ru_loc = gen( strRuLanguage ); wcout << TREX( L"hello world", ru_loc ) << endl; cout << "Stop Boost.Locale proba" << endl;
File paths: g:\source\boost_locale\languages\en\LC_MESSAGES\messages.mo g:\source\boost_locale\languages\ru\LC_MESSAGES\messages.mo
and I see in STDOUT following: Start Boost.Locale proba Hello world Localized Stop Boost.Locale proba Press any key to continue . . .
There no any russian strings in STDOUT. Why?
Hi, I guess you need to associate the locale ru_loc on the stream wcout. Vicente
participants (4)
-
Artyom Beilis
-
NtVisigoth
-
Viatcheslav.Sysoltsev@h-d-gmbh.de
-
Vicente J. Botet Escriba