Merge branch 'glib.fixtools.i18n' into 'master'

Tools: Correctly show translated messages on more recent Visual Studio builds

Closes #1169

See merge request GNOME/glib!895
This commit is contained in:
Philip Withnall 2019-06-18 10:18:31 +00:00
commit 1888deecfc
7 changed files with 41 additions and 17 deletions

View File

@ -26,6 +26,8 @@
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include "glib/glib-private.h"
static gboolean static gboolean
is_valid_module_name (const gchar *basename) is_valid_module_name (const gchar *basename)
{ {
@ -160,7 +162,7 @@ main (gint argc,
return 1; return 1;
} }
setlocale (LC_ALL, ""); setlocale (LC_ALL, GLIB_DEFAULT_LOCALE);
/* Be defensive and ensure we're linked to GObject */ /* Be defensive and ensure we're linked to GObject */
g_type_ensure (G_TYPE_OBJECT); g_type_ensure (G_TYPE_OBJECT);

View File

@ -28,7 +28,7 @@
#include <errno.h> #include <errno.h>
#include "gio-tool.h" #include "gio-tool.h"
#include "glib/glib-private.h"
void void
print_error (const gchar *format, ...) print_error (const gchar *format, ...)
@ -253,9 +253,20 @@ main (int argc, char **argv)
const char *command; const char *command;
gboolean do_help; gboolean do_help;
setlocale (LC_ALL, ""); #ifdef G_OS_WIN32
gchar *localedir;
#endif
setlocale (LC_ALL, GLIB_DEFAULT_LOCALE);
textdomain (GETTEXT_PACKAGE); textdomain (GETTEXT_PACKAGE);
#ifdef G_OS_WIN32
localedir = _glib_get_locale_dir ();
bindtextdomain (GETTEXT_PACKAGE, localedir);
g_free (localedir);
#else
bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR); bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
#endif
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

View File

@ -43,10 +43,7 @@
#include "gvdb/gvdb-builder.h" #include "gvdb/gvdb-builder.h"
#include "gconstructor_as_data.h" #include "gconstructor_as_data.h"
#ifdef G_OS_WIN32
#include "glib/glib-private.h" #include "glib/glib-private.h"
#endif
typedef struct typedef struct
{ {
@ -754,7 +751,7 @@ main (int argc, char **argv)
gchar *tmp; gchar *tmp;
#endif #endif
setlocale (LC_ALL, ""); setlocale (LC_ALL, GLIB_DEFAULT_LOCALE);
textdomain (GETTEXT_PACKAGE); textdomain (GETTEXT_PACKAGE);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32

View File

@ -29,10 +29,7 @@
#include "gvdb/gvdb-builder.h" #include "gvdb/gvdb-builder.h"
#include "strinfo.c" #include "strinfo.c"
#ifdef G_OS_WIN32
#include "glib/glib-private.h" #include "glib/glib-private.h"
#endif
static void static void
strip_string (GString *string) strip_string (GString *string)
@ -2188,7 +2185,7 @@ main (int argc, char **argv)
gchar *tmp = NULL; gchar *tmp = NULL;
#endif #endif
setlocale (LC_ALL, ""); setlocale (LC_ALL, GLIB_DEFAULT_LOCALE);
textdomain (GETTEXT_PACKAGE); textdomain (GETTEXT_PACKAGE);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32

View File

@ -41,9 +41,7 @@
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <gi18n.h> #include <gi18n.h>
#ifdef G_OS_WIN32
#include "glib/glib-private.h" #include "glib/glib-private.h"
#endif
#if defined(HAVE_LIBELF) && defined(HAVE_MMAP) #if defined(HAVE_LIBELF) && defined(HAVE_MMAP)
#define USE_LIBELF #define USE_LIBELF
@ -610,7 +608,7 @@ main (int argc, char *argv[])
gchar *tmp; gchar *tmp;
#endif #endif
setlocale (LC_ALL, ""); setlocale (LC_ALL, GLIB_DEFAULT_LOCALE);
textdomain (GETTEXT_PACKAGE); textdomain (GETTEXT_PACKAGE);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32

View File

@ -25,9 +25,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef G_OS_WIN32
#include "glib/glib-private.h" #include "glib/glib-private.h"
#endif
static GSettingsSchemaSource *global_schema_source; static GSettingsSchemaSource *global_schema_source;
static GSettings *global_settings; static GSettings *global_settings;
@ -743,7 +741,7 @@ main (int argc, char **argv)
gchar *tmp; gchar *tmp;
#endif #endif
setlocale (LC_ALL, ""); setlocale (LC_ALL, GLIB_DEFAULT_LOCALE);
textdomain (GETTEXT_PACKAGE); textdomain (GETTEXT_PACKAGE);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32

View File

@ -84,4 +84,25 @@ typedef struct {
GLIB_AVAILABLE_IN_ALL GLIB_AVAILABLE_IN_ALL
GLibPrivateVTable *glib__private__ (void); 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__ */ #endif /* __GLIB_PRIVATE_H__ */