#303: Typo fixes from mathnerd314
[supertux.git] / src / tinygettext / findlocale.cpp
index 04d1fb4..dbcb961 100644 (file)
@@ -1,6 +1,6 @@
 /*
  findlocale-0.46.tar.gz from http://icculus.org/~aspirin/findlocale/
+
 Copyright (C) 2004 Adam D. Moss (the "Author").  All Rights Reserved.
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -26,6 +26,7 @@ use or other dealings in this Software without prior written authorization
 from the Author.
 
 */
+#include <config.h>
 
 #include <stdlib.h>
 #include <string.h>
@@ -36,6 +37,10 @@ from the Author.
 #include <winnt.h>
 #endif
 
+#ifdef MACOSX
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
 #include "findlocale.hpp"
 
 static int
@@ -151,7 +156,7 @@ accumulate_env(const char *name, FL_Locale *l) {
 #endif
 
 static void
-canonise_fl(FL_Locale *l) {
+canonize_fl(FL_Locale *l) {
   /* this function fixes some common locale-specifying mistakes */
   /* en_UK -> en_GB */
   if (l->lang && 0 == strcmp(l->lang, "en")) {
@@ -469,6 +474,32 @@ FL_FindLocale(FL_Locale **locale, FL_Domain /*domain*/) {
 #else
   /* assume unixoid */
   {
+#ifdef MACOSX
+    CFIndex sz;
+    CFArrayRef languages;
+    CFStringRef uxstylelangs;
+    char *uxsl;
+
+    /* get the languages from the user's presets */
+    languages = (CFArrayRef)CFPreferencesCopyValue(CFSTR("AppleLanguages"),
+      kCFPreferencesAnyApplication, kCFPreferencesCurrentUser,
+      kCFPreferencesAnyHost);
+
+    /* join the returned string array into a string separated by colons */
+    uxstylelangs = CFStringCreateByCombiningStrings(kCFAllocatorDefault,
+      languages, CFSTR(":"));
+
+    /* convert this string into a C string */
+    sz = CFStringGetLength(uxstylelangs) + 1;
+    uxsl = (char*)malloc(sz);
+    CFStringGetCString(uxstylelangs, uxsl, sz, kCFStringEncodingISOLatin1);
+
+    /* add it to the list */
+    if (accumulate_locstring(uxsl, rtn)) {
+      success = FL_CONFIDENT;
+    }
+    /* continue the UNIX method */
+#endif
     /* examples: */
     /* sv_SE.ISO_8859-1 */
     /* fr_FR.ISO8859-1 */
@@ -493,7 +524,7 @@ FL_FindLocale(FL_Locale **locale, FL_Domain /*domain*/) {
 #endif
 
   if (success != FL_FAILED) {
-    canonise_fl(rtn);
+    canonize_fl(rtn);
   }
 
   *locale = rtn;