diff options
author | Jens Verwiebe <info@jensverwiebe.de> | 2013-03-03 02:50:46 +0400 |
---|---|---|
committer | Jens Verwiebe <info@jensverwiebe.de> | 2013-03-03 02:50:46 +0400 |
commit | 1c5f18f42b4de1dcd90dcb134105db9e11d14d5a (patch) | |
tree | 1f5c836c6620d005e378433df282268ff46164a5 /intern | |
parent | b74c686c66f5b18f454422e1af2fed726ad4570f (diff) |
OSX: Get the current locale in objC-style
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 7 | ||||
-rw-r--r-- | intern/locale/boost_locale_wrapper.cpp | 23 | ||||
-rw-r--r-- | intern/locale/boost_locale_wrapper.h | 6 |
3 files changed, 13 insertions, 23 deletions
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 2d8070191c9..bc215ae4914 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -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() diff --git a/intern/locale/boost_locale_wrapper.cpp b/intern/locale/boost_locale_wrapper.cpp index ebd2dd652c7..ef22e31e3cf 100644 --- a/intern/locale/boost_locale_wrapper.cpp +++ b/intern/locale/boost_locale_wrapper.cpp @@ -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 diff --git a/intern/locale/boost_locale_wrapper.h b/intern/locale/boost_locale_wrapper.h index 4e3a1f848d2..22f3793ae67 100644 --- a/intern/locale/boost_locale_wrapper.h +++ b/intern/locale/boost_locale_wrapper.h @@ -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 |