+#if defined (__APPLE__)
+static gchar*
+get_darwin_locale (void)
+{
+ static gchar *darwin_locale = NULL;
+ CFLocaleRef locale = NULL;
+ CFStringRef locale_cfstr = NULL;
+ CFIndex len;
+ int i;
+
+ if (darwin_locale != NULL)
+ return g_strdup (darwin_locale);
+
+ locale = CFLocaleCopyCurrent ();
+
+ if (locale) {
+ locale_cfstr = CFLocaleGetIdentifier (locale);
+
+ if (locale_cfstr) {
+ len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1;
+ darwin_locale = (char *) malloc (len);
+ if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) {
+ free (darwin_locale);
+ CFRelease (locale);
+ darwin_locale = NULL;
+ return NULL;
+ }
+
+ for (i = 0; i < strlen (darwin_locale); i++)
+ if (darwin_locale [i] == '_')
+ darwin_locale [i] = '-';
+ }
+
+ CFRelease (locale);
+ }
+
+ return g_strdup (darwin_locale);
+}
+#endif
+