gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Sun Mar 20 17:54:25 EDT 2016


Updated	 via  https://github.com/Gnucash/gnucash/commit/2059f06f (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9854876c (commit)
	from  https://github.com/Gnucash/gnucash/commit/dca13d62 (commit)



commit 2059f06f272a2b019a0ffc275e3514c4777a272c
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 20 15:52:07 2016 -0700

    Open correct xea directory if user has worked around bug 725296
    
    Bug 725296 reports that setting LANG=sv_SE fails to set the language.
    This turns out to be an error in gettext, but it can be worked around
    by setting LANG=Swedish_Sweden. That broke looking up the localized
    account directory, so this special-cases "Swedish_Sweden" and
    "Swedish_Finland" when looking up the account directory.

diff --git a/src/gnome/assistant-hierarchy.c b/src/gnome/assistant-hierarchy.c
index 7074158..444a479 100644
--- a/src/gnome/assistant-hierarchy.c
+++ b/src/gnome/assistant-hierarchy.c
@@ -226,13 +226,25 @@ gnc_get_ea_locale_dir(const char *top_dir)
     int i;
 
 #ifdef PLATFORM_WIN32
-    /* On win32, setlocale() doesn't say anything useful. Use
-       glib's function instead. */
-    locale = g_win32_getlocale();
-    if (!locale)
+    /* On win32, setlocale() doesn't say anything useful, so we check
+     * g_win32_getlocale(). Unfortunately it checks the value of $LANG first,
+     * and the user might have worked around the absence of sv in gettext's
+     * Microsoft Conversion Array by setting it to "Swedish_Sweden", so first
+     * check that.
+     */
+    locale = g_getenv("LANG");
+    if (g_strcmp0(locale, "Swedish_Sweden") == 0)
+        locale = g_strdup("sv_SV");
+    elae if (g_strcmp0(locale, "Swedish_Finland") == 0)
+        locale =g_strdup("sv_FI");
+    else
     {
-        PWARN ("Couldn't retrieve locale. Falling back to default one.");
-        locale = g_strdup ("C");
+        locale = g_win32_getlocale();
+        if (!locale)
+        {
+            PWARN ("Couldn't retrieve locale. Falling back to default one.");
+            locale = g_strdup ("C");
+        }
     }
 #elif defined PLATFORM_OSX
     locale = mac_locale();

commit 9854876c702bca212d31221fba4f4126445bb25a
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 20 15:11:06 2016 -0700

    OSX: Get the locale for account trees from the OS instead of setlocale().
    
    It's possible for OSX to create locales that while legal aren't
    supported by setlocale, and we have account trees for some of these.
    Retrieving the locale from NSLocale ignores the fixup done in
    gnucash-bin to ensure that a reasonable and supported locale is used.

diff --git a/src/gnome/assistant-hierarchy.c b/src/gnome/assistant-hierarchy.c
index 7b8e641..7074158 100644
--- a/src/gnome/assistant-hierarchy.c
+++ b/src/gnome/assistant-hierarchy.c
@@ -31,6 +31,10 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifdef PLATFORM_OSX
+#include <Foundation/Foundation.h>
+#endif
+
 #include "gnc-account-merge.h"
 #include "dialog-new-user.h"
 #include "dialog-options.h"
@@ -182,6 +186,36 @@ set_final_balance (GHashTable *hash, Account *account, gnc_numeric in_balance)
     g_hash_table_insert (hash, account, balance);
 }
 
+#ifdef PLATFORM_OSX
+/* Repeat retrieving the locale from defaults in case it was overridden in
+ * gnucash-bin because it wasn't a supported POSIX locale.
+ */
+static char*
+mac_locale()
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    NSLocale* locale = [NSLocale currentLocale];
+    NSString* locale_str;
+    char *retval = NULL;
+    @try
+    {
+        locale_str =[[[locale objectForKey: NSLocaleLanguageCode]
+		       stringByAppendingString: @"_"]
+		      stringByAppendingString:
+		      [locale objectForKey: NSLocaleCountryCode]];
+    }
+    @catch (NSException *err)
+    {
+	locale_str = @"_";
+    }
+/* If we didn't get a valid current locale, the string will be just "_" */
+    if ([locale_str isEqualToString: @"_"])
+	locale_str = @"en_US";
+    retval = g_strdup([locale_str UTF8String]);
+    [pool drain];
+    return retval;
+}
+#endif
 static gchar*
 gnc_get_ea_locale_dir(const char *top_dir)
 {
@@ -191,10 +225,7 @@ gnc_get_ea_locale_dir(const char *top_dir)
     struct stat buf;
     int i;
 
-#ifdef HAVE_LC_MESSAGES
-    locale = g_strdup(setlocale(LC_MESSAGES, NULL));
-#else
-# ifdef G_OS_WIN32
+#ifdef PLATFORM_WIN32
     /* On win32, setlocale() doesn't say anything useful. Use
        glib's function instead. */
     locale = g_win32_getlocale();
@@ -203,14 +234,10 @@ gnc_get_ea_locale_dir(const char *top_dir)
         PWARN ("Couldn't retrieve locale. Falling back to default one.");
         locale = g_strdup ("C");
     }
+#elif defined PLATFORM_OSX
+    locale = mac_locale();
 # else
-    /*
-     * Mac OS X 10.1 and earlier, not only doesn't have LC_MESSAGES
-     * setlocale can sometimes return NULL instead of "C"
-     */
-    locale = g_strdup(setlocale(LC_ALL, NULL) ?
-                      setlocale(LC_ALL, NULL) : "C");
-# endif
+    locale = g_strdup(setlocale(LC_MESSAGES, NULL));
 #endif
 
     i = strlen(locale);



Summary of changes:
 src/gnome/assistant-hierarchy.c | 73 +++++++++++++++++++++++++++++++----------
 1 file changed, 56 insertions(+), 17 deletions(-)



More information about the gnucash-changes mailing list