]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Improvements for MacOS X.
authorBruno Haible <bruno@clisp.org>
Tue, 7 Sep 2004 13:01:58 +0000 (13:01 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:55 +0000 (12:11 +0200)
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/langprefs.c
gettext-runtime/intl/localename.c

index b1d6f98bdfe93e4ba0db30f37f74deda949cbb3f..e87128e289cdfa3b8fefb3e1a576d2a607ffe15b 100644 (file)
@@ -1,3 +1,9 @@
+2004-09-06  Bruno Haible  <bruno@clisp.org>
+
+       * 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  <bruno@clisp.org>
 
        * langprefs.c: New file.
index 2dcfeb625dc67c35e080a93dc63fdeff9ceb1274..9bdfacd49ac6f25018506edea4698f928f003e6b 100644 (file)
@@ -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))
index 489e8ef279c60d1ee7a198c2e0f45b26e5069df8..f61cecea6d7872bcac78f946b4b8c1952019e819 100644 (file)
 #include <stdlib.h>
 #include <locale.h>
 
-#if HAVE_CFLOCALECOPYCURRENT
+#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
 # include <string.h>
 # include <CFString.h>
-# include <CFLocale.h>
+# if HAVE_CFLOCALECOPYCURRENT
+#  include <CFLocale.h>
+# elif HAVE_CFPREFERENCESCOPYAPPVALUE
+#  include <CFPreferences.h>
+# 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";
       }