
#include <boost/locale.hpp> #include <iostream> //#include <ctime> using namespace boost::locale; int main() { generator gen; //std::locale::global(gen("snthsnth")); // no exception std::locale::global(gen("en_US.UTF-8")); double now = time(0); std::cout << "Today is " << as::date << now << std::endl << "Current time is " << as::time << now << std::endl << "The current weekday is " << as::ftime("%A") << now << std::endl; std::cin.get(); } http://cppcms.sourceforge.net/boost_locale/html/formatting_and_parsing.html I get warnings about converting from time_t to double (which I rather expected) and then get basic, double formatted output: Today is 1.3029e+009 Current time is 1.3029e+009 The current weekday is 1.3029e+009

On 4/15/2011 12:33 PM, Noah Roberts wrote:
#include <boost/locale.hpp>
#include <iostream> //#include <ctime>
using namespace boost::locale;
int main() { generator gen; //std::locale::global(gen("snthsnth")); // no exception std::locale::global(gen("en_US.UTF-8"));
double now = time(0);
std::cout << "Today is " << as::date << now << std::endl << "Current time is " << as::time << now << std::endl << "The current weekday is " << as::ftime("%A") << now << std::endl;
std::cin.get(); }
http://cppcms.sourceforge.net/boost_locale/html/formatting_and_parsing.html
I get warnings about converting from time_t to double (which I rather expected) and then get basic, double formatted output:
Today is 1.3029e+009 Current time is 1.3029e+009 The current weekday is 1.3029e+009
Should note also when I use "auto now = time(0);" I get integer output, not formatted dates and times.

#include <boost/locale.hpp>
#include <iostream> //#include <ctime>
using namespace boost::locale;
int main() { generator gen; //std::locale::global(gen("snthsnth")); // no exception std::locale::global(gen("en_US.UTF-8"));
double now = time(0);
std::cout << "Today is " << as::date << now << std::endl << "Current time is " << as::time << now << std::endl << "The current weekday is " << as::ftime("%A") << now << std::endl;
std::cin.get(); }
http://cppcms.sourceforge.net/boost_locale/html/formatting_and_parsing.html
I get warnings about converting from time_t to double (which I rather expected) and then get basic, double formatted output:
Today is 1.3029e+009 Current time is 1.3029e+009 The current weekday is 1.3029e+009
Changing the global locale does not affect the currently created streams so what you need is to add a line. std::cout.imbue(std::locale()); // Now global locale imbued to stream as well. and then std::cout << as::date << now;
//std::locale::global(gen("snthsnth")); // no exception
It is intentional. If fallbacks to some generic locale if it is not found. It allows you to handle at least messages for non-supported locales (lets say Epseranto) Artyom

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Noah Roberts Sent: Friday, April 15, 2011 8:43 PM To: boost@lists.boost.org Subject: Re: [boost] [locale] Strange(?) result in example code
On 4/15/2011 12:38 PM, Artyom wrote:
std::cout.imbue(std::locale()); // Now global locale imbued to stream as well.
LOL, DUH! OK. Thanks.
Well join the club - I've fallen into this pit recently :-( Am I correct in thinking that the reason is that std::cout is constructed *before* the new locale is 'globalled'? And so std::cerr needs imbuing too but that fstream and stringstreams constructed after the std::locale::global("en_US.UTF-8") statement will get the new locale? Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com

Paul A. Bristow wrote:
To: boost@lists.boost.org Sent: Sat, April 16, 2011 2:40:10 PM Subject: Re: [boost] [locale] Strange(?) result in example code
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Noah Roberts Sent: Friday, April 15, 2011 8:43 PM To: boost@lists.boost.org Subject: Re: [boost] [locale] Strange(?) result in example code
On 4/15/2011 12:38 PM, Artyom wrote:
std::cout.imbue(std::locale()); // Now global locale imbued to stream as well.
LOL, DUH! OK. Thanks.
Well join the club - I've fallen into this pit recently :-(
Am I correct in thinking that the reason is that std::cout is constructed *before* the new locale is 'globalled'?
Yes.
And so std::cerr needs imbuing too but that fstream and stringstreams constructed after the std::locale::global("en_US.UTF-8") statement will get the new locale?
Yes. See 27.4.2.3/4 of C++03. HTH, Gevorg

std::cout.imbue(std::locale()); // Now global locale imbued to stream as
well.
LOL, DUH! OK. Thanks.
Well join the club - I've fallen into this pit recently :-(
Am I correct in thinking that the reason is that std::cout is constructed *before* the new locale is 'globalled'?
Yes.
And so std::cerr needs imbuing too but that fstream and stringstreams constructed after the std::locale::global("en_US.UTF-8") statement will get the new locale?
Yes, basically if you want to do it fully for standard library and boost: std::locale::global(loc); std::cout.imbue(loc); std::cin.imbue(loc); std::cerr.imbue(loc); std::clog.imbue(loc); std::wcout.imbue(loc); std::wcin.imbue(loc); std::wcerr.imbue(loc); std::wclog.imbue(loc); // this is for boost filesystem boost::filesystem::path::imbue(loc);
Paul
Artyom

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Artyom Sent: Saturday, April 16, 2011 2:32 PM To: boost@lists.boost.org Subject: Re: [boost] [locale] Strange(?) result in example code
std::cout.imbue(std::locale()); // Now global locale imbued to stream as
well.
LOL, DUH! OK. Thanks.
Well join the club - I've fallen into this pit recently :-(
Am I correct in thinking that the reason is that std::cout is constructed *before* the new locale is 'globalled'?
Yes.
And so std::cerr needs imbuing too but that fstream and stringstreams constructed after the std::locale::global("en_US.UTF-8") statement will get the new locale?
Yes, basically if you want to do it fully for standard library and boost:
std::locale::global(loc); std::cout.imbue(loc); std::cin.imbue(loc); std::cerr.imbue(loc); std::clog.imbue(loc);
std::wcout.imbue(loc); std::wcin.imbue(loc); std::wcerr.imbue(loc); std::wclog.imbue(loc);
// this is for boost filesystem boost::filesystem::path::imbue(loc);
Thanks for this confirmation. This seems such an obviously attractive pit, I am sure Noah and I won't be the last to fall in it ;-) I think Boost.Locale docs would be a good place to remind users of locale of its existence, including a reference to 27.4.2.3/4 of C++03. Would you like to add it as a [warning ....] while you are crossing the 't's and dotting the 'i's ? Thanks Paul --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com

Yes, basically if you want to do it fully for standard library and boost:
std::locale::global(loc); std::cout.imbue(loc); std::cin.imbue(loc); std::cerr.imbue(loc); std::clog.imbue(loc);
std::wcout.imbue(loc); std::wcin.imbue(loc); std::wcerr.imbue(loc); std::wclog.imbue(loc);
// this is for boost filesystem boost::filesystem::path::imbue(loc);
Thanks for this confirmation.
This seems such an obviously attractive pit, I am sure Noah and I won't be the last to fall in it ;-)
I think Boost.Locale docs would be a good place to remind users of locale of its existence, including a reference to 27.4.2.3/4 of C++03.
It will be added to the tutorial Artyom

Paul A. Bristow wrote:
On Behalf Of Artyom
Yes, basically if you want to do it fully for standard library and boost:
std::locale::global(loc); std::cout.imbue(loc); std::cin.imbue(loc); std::cerr.imbue(loc); std::clog.imbue(loc);
std::wcout.imbue(loc); std::wcin.imbue(loc); std::wcerr.imbue(loc); std::wclog.imbue(loc);
// this is for boost filesystem boost::filesystem::path::imbue(loc);
Thanks for this confirmation.
This seems such an obviously attractive pit, I am sure Noah and I won't be the last to fall in it ;-)
I think Boost.Locale docs would be a good place to remind users of locale of its existence, including a reference to 27.4.2.3/4 of C++03.
Would you like to add it as a [warning ....]?
What about library provided functions, such as the following? void imbue_globally(_locale) { std::locale::global(_locale); std::cout.imbue(_locale); std::cin.imbue(_locale); std::cerr.imbue(_locale); std::clog.imbue(_locale); } void wimbue_globally(_locale) { std::locale::global(_locale); std::wcout.imbue(_locale); std::wcin.imbue(_locale); std::wcerr.imbue(_locale); std::wclog.imbue(_locale); } _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

What about library provided functions, such as the following?
void imbue_globally(_locale) { std::locale::global(_locale); std::cout.imbue(_locale); std::cin.imbue(_locale); std::cerr.imbue(_locale); std::clog.imbue(_locale); }
void wimbue_globally(_locale) { std::locale::global(_locale); std::wcout.imbue(_locale); std::wcin.imbue(_locale); std::wcerr.imbue(_locale); std::wclog.imbue(_locale); }
It should be rather
void imbue_globally(_locale) { std::locale::global(_locale);
std::cout.imbue(_locale); std::cin.imbue(_locale); std::cerr.imbue(_locale); std::clog.imbue(_locale);
std::wcout.imbue(_locale); std::wcin.imbue(_locale); std::wcerr.imbue(_locale); std::wclog.imbue(_locale);
boost::filesystem::path::imbue(_locale);
}
Of course when you use boost.filesyste, Artyom

Artyom wrote:
What about library provided functions, such as the following?
void imbue_globally(_locale) { std::locale::global(_locale); std::cout.imbue(_locale); std::cin.imbue(_locale); std::cerr.imbue(_locale); std::clog.imbue(_locale); }
void wimbue_globally(_locale) { std::locale::global(_locale); std::wcout.imbue(_locale); std::wcin.imbue(_locale); std::wcerr.imbue(_locale); std::wclog.imbue(_locale); }
It should be rather
void imbue_globally(_locale) { std::locale::global(_locale);
std::cout.imbue(_locale); std::cin.imbue(_locale); std::cerr.imbue(_locale); std::clog.imbue(_locale);
std::wcout.imbue(_locale); std::wcin.imbue(_locale); std::wcerr.imbue(_locale); std::wclog.imbue(_locale);
boost::filesystem::path::imbue(_locale);
}
Of course when you use boost.filesyste,
I disagree. For those that don't use both narrow and wide streams or Boost.Filesystem, such a function would increase binary size unnecessarily. _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

It should be rather
void imbue_globally(_locale) { std::locale::global(_locale);
std::cout.imbue(_locale); std::cin.imbue(_locale); std::cerr.imbue(_locale); std::clog.imbue(_locale);
std::wcout.imbue(_locale); std::wcin.imbue(_locale); std::wcerr.imbue(_locale); std::wclog.imbue(_locale);
boost::filesystem::path::imbue(_locale);
}
Of course when you use boost.filesyste,
I disagree. For those that don't use both narrow and wide streams or Boost.Filesystem, such a function would increase binary size unnecessarily.
Of course, nobody need to link with boost.filesystem All I wanted to mention that many libraries have their own "global locale" Thats it. Artyom

What version of xgettext? I've tried a couple different downloads and neither of them work as explained in the docs. For example, "xgettext --keyword=translate:1,1t main.cpp" does nothing. I have to remove everything after ':' or at least remove ',1t' to get a messages.po file. Not enough of course for the context and plural versions. Trying to do this on Windows 7.

What version of xgettext? I've tried a couple different downloads and neither of them work as explained in the docs. For example, "xgettext --keyword=translate:1,1t main.cpp" does nothing. I have to remove everything after ':' or at least remove ',1t' to get a messages.po file. Not enough of course for the context and plural versions.
Trying to do this on Windows 7.
Ok the best is the latest (I think 0.17) the versions below 0.16 I think do not support context part. I'll search for up-to-date downloads of gettext tools for windows and point to them in the documentation. Artyom
participants (5)
-
Artyom
-
Gevorg Voskanyan
-
Noah Roberts
-
Paul A. Bristow
-
Stewart, Robert