OSX: Get the current locale in objC-style
authorJens Verwiebe <info@jensverwiebe.de>
Sat, 2 Mar 2013 22:50:46 +0000 (22:50 +0000)
committerJens Verwiebe <info@jensverwiebe.de>
Sat, 2 Mar 2013 22:50:46 +0000 (22:50 +0000)
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/locale/boost_locale_wrapper.cpp
intern/locale/boost_locale_wrapper.h

index 2d8070191c95cda5ddf865b0dc8893756b4152fe..bc215ae49147cd22339aea9dd751cd7850170a17 100644 (file)
@@ -542,6 +542,7 @@ int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
 
 #pragma mark initialization/finalization
 
+const char *user_locale; // Global current user locale
 
 GHOST_SystemCocoa::GHOST_SystemCocoa()
 {
@@ -580,6 +581,12 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
        rstring = NULL;
        
        m_ignoreWindowSizedMessages = false;
+       
+       //Get current locale
+       CFLocaleRef myCFLocale = CFLocaleCopyCurrent();
+       NSLocale *myNSLocale = (NSLocale *)CFBridgingRelease(myCFLocale);
+       NSString *nsIdentifier = [myNSLocale localeIdentifier];
+       user_locale = [nsIdentifier UTF8String];        
 }
 
 GHOST_SystemCocoa::~GHOST_SystemCocoa()
index ebd2dd652c70e8713becd2bf3c4ad441418d5e0c..ef22e31e3cf34cda3e06d77f53e31e9e3b129966 100644 (file)
@@ -66,28 +66,7 @@ void bl_locale_set(const char *locale)
                }
                else {
 #ifdef __APPLE__
-                       // workaround to get osx system locale from user defaults
-                       FILE *fp;
-                       std::string locale_osx = "";
-                       char result[16];
-                       int result_len = 0;
-
-                       fp = popen("defaults read .GlobalPreferences AppleLocale", "r");
-
-                       if (fp) {
-                               result_len = fread(result, 1, sizeof(result) - 1, fp);
-
-                               if (result_len > 0) {
-                                       result[result_len - 1] = '\0'; // \0 terminate and remove \n
-                                       locale_osx = std::string(result) + std::string(".UTF-8");
-                               }
-
-                               pclose(fp);
-                       }
-
-                       if (locale_osx == "")
-                               fprintf(stderr, "Locale set: failed to read AppleLocale read from defaults\n");
-
+                       std::string locale_osx = user_locale + std::string(".UTF-8");
                        _locale = gen(locale_osx.c_str());
                        std::locale::global(_locale);
 #else
index 4e3a1f848d22a1eb80ca25ab6c11223516eb04a2..22f3793ae6774c91e2fac539a9c531f161aec703 100644 (file)
@@ -42,7 +42,11 @@ void bl_locale_init(const char *messages_path, const char *default_domain);
 void bl_locale_set(const char *locale);
 const char *bl_locale_get(void);
 const char *bl_locale_pgettext(const char *msgctxt, const char *msgid);
-
+       
+#ifdef __APPLE__
+extern const char *user_locale; // pulled from Ghost_SystemCocoa
+#endif
+       
 #ifdef __cplusplus
 }
 #endif