Is there any standard way doing locale setting across platforms per thread? I see that xlocale provides uselocale, but it is not supported in Windows. There is "_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);" in windows, after which setlocale works on per thread basis. My question is, is there a library that provides these locale specific manipulations in a platform independent way??? Or some other way of doing it?
Thanks, Gokul.
I've had the same problem and I eventually wrote some small cross-compatibility code for it. I tried to follow the specification as close as possible, but it does have a few limitations.
In this code newlocale does not allow you to specify a base locale and you're also not able to mix the category masks. But for some basic switching between different locales this should be enough.
Put that code in your project and you'll be able to switch the locale per-thread on any platform like this:
Boost::Locale provides a locale interface which is cross-platform, based on the iconv library. It might not be your ideal interface if you're hoping for C standard library functions to behave appropriately as soon as you set the locale. You will, instead, manually manage locales as objects, and explicitly use them. You explicitly generate locales and use them to create comparators and whatever else you need that's locale specific.
On the one hand, this means any previously developed code you wrote which relies on locale being specific will have to be rewritten. On the other hand, there are many fewer gotchas hidden under the hood, as you're explicitly handling what language/encoding is used where.