glib-private.h: Set the appropriate string for setlocale()

On Windows, in particular the CRTs on and after Visual Studio 2012, it
is not enough just to do setlocale (LC_ALL, "") to set the default
system locale, which results in the tools that use the translated
messages to show unreadable messages when running the commmand line
tools.

This adds an entry in glib-private.h.in which denotes the appropriate
string to use for setlocale() to set the default system locale by
setting it to ".ACP" if we are building on Windows and "" for
other systems (as we are doing now).

The tools in gio/ will be updated in the next commit to make use of this
entry so that the translated messages can be shown correctly.
This commit is contained in:
Chun-wei Fan 2019-06-05 16:34:57 +08:00
parent 833d38b40f
commit 3e5d1bd6ff

View File

@ -84,4 +84,25 @@ typedef struct {
GLIB_AVAILABLE_IN_ALL
GLibPrivateVTable *glib__private__ (void);
/* Please see following for the use of ".ACP" over ""
* on Windows, although both are accepted at compile-time
* but "" renders translated console messages unreadable if
* built with Visual Studio 2012 and later (this is, unfortunately,
* undocumented):
*
* https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale
* https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525881
* https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525900
*
* Additional related items:
* https://stackoverflow.com/questions/22604329/php-5-5-setlocale-not-working-in-cli-on-windows
* https://bugs.php.net/bug.php?id=66265
*/
#ifdef G_OS_WIN32
# define GLIB_DEFAULT_LOCALE ".ACP"
#else
# define GLIB_DEFAULT_LOCALE ""
#endif
#endif /* __GLIB_PRIVATE_H__ */