Is there a way to access the locale used by gettext under windows?
I have a program where i18n is handled by gettext. The program works fine, however for some reason I need to know the name of the locale used by gettext at runtime (something like 'fr_FR') under win32.
I looked into gettext sources, and there is a quite frightening function that computes it on all platforms (gl_locale_name, in a C 开发者_如何学Pythonfile called "localename.h/c"). However, this file does not seem to be installed alongside gettext or libintl, so I can't seem to call the function. Is there another function provided by gettext to get this value ? Or in another package (boost, glib, anything ?)
(On a related note, there is a thing called std::locale in the C++ standard library, and according to the doc calling std::locale("") should create a locale with the settings of the system, unless I am mistaken ... but then the name is 'C' under windows. Is it a viable way of getting the locale name ? What I am doing wrong ?)
On Windows typically used function GetUserDefaultLCID
which returns you integer value of locale identifier. To convert from LCID to string like 'fr_FR' you need to map it based on the info from http://msdn.microsoft.com/en-us/library/ms776260
Turns out the "gl_locale_name" function was not part of gettext directly, but rather part of gnulib - http://www.gnu.org/software/gnulib. I just discovered the package today.
So getting the infamous localename.h header in my project was a matter of
gnulib-tool --import localename
Then the gl_locale_name function works just fine when cross-compiling.
Thanks to everyone for the answers !
You can use setlocale(NULL) to pull the locale from the CRT. But from Windows, I've got no idea. Also, gettext is a pretty generic function and you're going to have to be more specific about what gettext.
精彩评论