mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user