gnucash maint: Fix erratic localization of dates on Windows.
John Ralls
jralls at code.gnucash.org
Mon Feb 11 19:35:25 EST 2019
Updated via https://github.com/Gnucash/gnucash/commit/bfadfd7d (commit)
from https://github.com/Gnucash/gnucash/commit/8f88b7f2 (commit)
commit bfadfd7d6df15c90262e12c7a11831c8cbd874d1
Author: John Ralls <jralls at ceridwen.us>
Date: Mon Feb 11 16:24:03 2019 -0800
Fix erratic localization of dates on Windows.
Date format selection on Windows relies on Windows National Language
functions and those are unaffected by the POSIX setlocale(). We have
in the past relied upon gtk initialization to handle this but it has
not been reliable since the move to Gtk3. Note that this applies only
when the locale is set via a Unix-style environment variable (typically
LANG) or in the environment file; it's unnecessary and ignored when
using the localization settings in Region & Language.
diff --git a/gnucash/gnucash-bin.c b/gnucash/gnucash-bin.c
index a4113e453..bfd135e3f 100644
--- a/gnucash/gnucash-bin.c
+++ b/gnucash/gnucash-bin.c
@@ -55,6 +55,9 @@
#include "gnc-session.h"
#include "engine-helpers-guile.h"
#include "swig-runtime.h"
+#ifdef __MINGW32__
+#include <Windows.h>
+#endif
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;
@@ -771,6 +774,35 @@ gnc_log_init()
}
}
+#ifdef __MINGW32__
+/* Set the Win32 internal localization for the main thread if the
+ * locale has been overridden in the environment. Note that this is
+ * separate from what setlocale() does; that only affects POSIX
+ * functions and does *not* set the Windows locale.
+ */
+static void
+set_win32_thread_locale()
+{
+ gunichar2* wlocale = NULL;
+ char *locale = NULL;
+ int len = 0;
+ if (((locale = getenv ("LC_ALL")) == NULL || locale[0] == '\0')
+ && ((locale = getenv ("LC_MESSAGES")) == NULL || locale[0] == '\0')
+ && ((locale = getenv ("LANG")) == NULL || locale[0] == '\0'))
+ return;
+ len = strchr(locale, '.') - locale;
+ locale[2] = '-';
+ wlocale = g_utf8_to_utf16 (locale, len, NULL, NULL, NULL);
+ if (IsValidLocaleName(wlocale))
+ {
+ LCID lcid = LocaleNameToLCID(wlocale, LOCALE_ALLOW_NEUTRAL_NAMES);
+ SetThreadLocale(lcid);
+ }
+ g_free(locale);
+ g_free(wlocale);
+}
+#endif
+
int
main(int argc, char ** argv)
{
@@ -798,6 +830,9 @@ main(int argc, char ** argv)
gnc_environment_setup();
#ifndef MAC_INTEGRATION /* setlocale already done */
sys_locale = g_strdup (setlocale (LC_ALL, ""));
+#ifdef __MINGW32__
+ set_win32_thread_locale();
+#endif
if (!sys_locale)
{
g_print ("The locale defined in the environment isn't supported. "
Summary of changes:
gnucash/gnucash-bin.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
More information about the gnucash-changes
mailing list