
On Sun, 11 Apr 2010 12:25:53 -0700 (PDT), Artyom wrote:
Now that *that* part (not crashing) is fixed, I'm running into another problem. I can see the .mo file being loaded; excellent! But when I try to translate a string, the translation mechanism fails to find it! This only happens when i set the locale statically. If I set it just before using translate() it works fine.
Here is the repro code: http://www.doc.ic.ac.uk/~awl03/locale_test2.zip
To see the different situations, change which commentted line declaring LocaleSetup.
Ok, you are right, I managed to reproduce it. Looks like something overerites the created locale with other one.
Maybe standard library defines global locale after it is defined in the constructor and this is just a question of an order of operation. I don't know I'll try to figure out.
I'll happily test any fix you come up with.
Note: I've tested on Linux and Windows with GCC with both static and dynamic libraries, this works. Looks like it happens only with MSVC.
In any case... I don't think that defining the global locale in static constructor is generally good idea.
Possibly not but commonly done. My workaround is to declare a static *local variable* instance of LocalSetup inside DllMain. This is created at runtime, unlike true static variables which are created at loadtime.
For unit test you may use the trick I described with testing if the current locale has boost::locale::info facet.
Thanks for the tips :) Alex