OSX/locale: workaround to get osx system locale from user defaults
authorJens Verwiebe <info@jensverwiebe.de>
Wed, 21 Nov 2012 13:54:54 +0000 (13:54 +0000)
committerJens Verwiebe <info@jensverwiebe.de>
Wed, 21 Nov 2012 13:54:54 +0000 (13:54 +0000)
intern/locale/boost_locale_wrapper.cpp

index ec2976f19b9fdee8e9bb1ad0001b01fd11ecbbc3..7b317da1edf2edeaa0fbad768052c44f078b94c1 100644 (file)
 
 #include "boost_locale_wrapper.h"
 
+#if defined (__APPLE__)
+       #include "stdio.h"
+#endif
+
 static std::string messages_path;
 static std::string default_domain;
 
@@ -60,7 +64,19 @@ void bl_locale_set(const char *locale)
                std::locale::global(gen(locale));
        }
        else {
+#if defined (__APPLE__)
+               // workaround to get osx system locale from user defaults
+               FILE* fp;
+               char result [10];
+               char osx_locale [10];
+               fp = popen("defaults read .GlobalPreferences AppleLocale","r");
+               fread(result,1,sizeof(result),fp);
+               fclose (fp);
+               sprintf(osx_locale, """%s.UTF-8""", result);
+               std::locale::global(gen(osx_locale));
+#else
                std::locale::global(gen(""));
+#endif
        }
        // Note: boost always uses "C" LC_NUMERIC by default!
 }