From: Bruno Haible Date: Tue, 7 Sep 2004 13:01:58 +0000 (+0000) Subject: Improvements for MacOS X. X-Git-Tag: v0.14.2~233 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cbca684757dea43cfb950158c0a34e33ead0cbc;p=thirdparty%2Fgettext.git Improvements for MacOS X. --- diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index b1d6f98bd..e87128e28 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,9 @@ +2004-09-06 Bruno Haible + + * localename.c (_nl_locale_name): Add code for MacOS X versions that + don't have the CFLocaleCopyCurrent() function. + * langprefs.c (_nl_language_preferences): Make code more robust. + 2004-09-05 Bruno Haible * langprefs.c: New file. diff --git a/gettext-runtime/intl/langprefs.c b/gettext-runtime/intl/langprefs.c index 2dcfeb625..9bdfacd49 100644 --- a/gettext-runtime/intl/langprefs.c +++ b/gettext-runtime/intl/langprefs.c @@ -54,10 +54,11 @@ _nl_language_preferences (void) if (!cache_initialized) { - CFPropertyListRef preferences = + CFTypeRef preferences = CFPreferencesCopyAppValue (CFSTR ("AppleLanguages"), kCFPreferencesCurrentApplication); - if (CFGetTypeID (preferences) == CFArrayGetTypeID ()) + if (preferences != NULL + && CFGetTypeID (preferences) == CFArrayGetTypeID ()) { CFArrayRef prefArray = (CFArrayRef)preferences; int n = CFArrayGetCount (prefArray); @@ -68,7 +69,8 @@ _nl_language_preferences (void) for (i = 0; i < n; i++) { CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); - if (CFGetTypeID (element) == CFStringGetTypeID () + if (element != NULL + && CFGetTypeID (element) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)element, buf, sizeof (buf), kCFStringEncodingASCII)) @@ -97,7 +99,8 @@ _nl_language_preferences (void) { CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); - if (CFGetTypeID (element) == CFStringGetTypeID () + if (element != NULL + && CFGetTypeID (element) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)element, buf, sizeof (buf), kCFStringEncodingASCII)) diff --git a/gettext-runtime/intl/localename.c b/gettext-runtime/intl/localename.c index 489e8ef27..f61cecea6 100644 --- a/gettext-runtime/intl/localename.c +++ b/gettext-runtime/intl/localename.c @@ -27,10 +27,14 @@ #include #include -#if HAVE_CFLOCALECOPYCURRENT +#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE # include # include -# include +# if HAVE_CFLOCALECOPYCURRENT +# include +# elif HAVE_CFPREFERENCESCOPYAPPVALUE +# include +# endif #endif #if defined _WIN32 || defined __WIN32__ @@ -731,7 +735,7 @@ _nl_locale_name (int category, const char *categoryname) /* We use C as the default domain. POSIX says this is implementation defined. */ -# if !(HAVE_CFLOCALECOPYCURRENT || defined(WIN32)) +# if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined(WIN32)) return "C"; @@ -742,21 +746,33 @@ _nl_locale_name (int category, const char *categoryname) context, because message catalogs are not specific to a single codeset. */ -# if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */ - +# if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE + /* MacOS X 10.2 or newer */ { /* Cache the locale name, since CoreFoundation calls are expensive. */ static const char *cached_localename; if (cached_localename == NULL) { + char namebuf[256]; +# if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */ CFLocaleRef locale = CFLocaleCopyCurrent (); CFStringRef name = CFLocaleGetIdentifier (locale); - char namebuf[256]; - if (CFStringGetCString (name, namebuf, sizeof(namebuf), kCFStringEncodingASCII)) + if (CFStringGetCString (name, namebuf, sizeof(namebuf), + kCFStringEncodingASCII)) cached_localename = strdup (namebuf); CFRelease (locale); +# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ + CFTypeRef value = + CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), + kCFPreferencesCurrentApplication); + if (value != NULL + && CFGetTypeID (value) == CFStringGetTypeID () + && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), + kCFStringEncodingASCII)) + cached_localename = strdup (namebuf); +# endif if (cached_localename == NULL) cached_localename = "C"; }