diff options
Diffstat (limited to 'intern/locale')
-rw-r--r-- | intern/locale/CMakeLists.txt | 5 | ||||
-rw-r--r-- | intern/locale/SConscript | 4 | ||||
-rw-r--r-- | intern/locale/boost_locale_wrapper.cpp | 3 | ||||
-rw-r--r-- | intern/locale/boost_locale_wrapper.h | 6 | ||||
-rw-r--r-- | intern/locale/osx_user_locale.mm | 22 |
5 files changed, 37 insertions, 3 deletions
diff --git a/intern/locale/CMakeLists.txt b/intern/locale/CMakeLists.txt index 217fe9a8c71..5d70c449234 100644 --- a/intern/locale/CMakeLists.txt +++ b/intern/locale/CMakeLists.txt @@ -36,6 +36,11 @@ set(SRC boost_locale_wrapper.h ) +if(APPLE) + # Cocoa code to read the locale on OSX + list(APPEND SRC osx_user_locale.mm) +endif() + if(WITH_HEADLESS) add_definitions(-DWITH_HEADLESS) endif() diff --git a/intern/locale/SConscript b/intern/locale/SConscript index 24828c120ec..02b4d6cda1b 100644 --- a/intern/locale/SConscript +++ b/intern/locale/SConscript @@ -29,6 +29,10 @@ Import('env') sources = env.Glob('*.cpp') +if env['OURPLATFORM'] in ['darwin']: + # Cocoa code to read user locale on OSX + sources.append('osx_user_locale.mm') + incs = '.' defs = [] diff --git a/intern/locale/boost_locale_wrapper.cpp b/intern/locale/boost_locale_wrapper.cpp index 25843d60578..5eb2f7fe9d9 100644 --- a/intern/locale/boost_locale_wrapper.cpp +++ b/intern/locale/boost_locale_wrapper.cpp @@ -65,8 +65,7 @@ void bl_locale_set(const char *locale) } else { #if defined(__APPLE__) && !defined(WITH_HEADLESS) && !defined(WITH_GHOST_SDL) - extern char GHOST_user_locale[128]; // pulled from Ghost_SystemCocoa - std::string locale_osx = GHOST_user_locale + std::string(".UTF-8"); + std::string locale_osx = osx_user_locale() + std::string(".UTF-8"); _locale = gen(locale_osx.c_str()); #else _locale = gen(""); diff --git a/intern/locale/boost_locale_wrapper.h b/intern/locale/boost_locale_wrapper.h index ff3645a5983..f7bc7b45eb6 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); - + +#if defined(__APPLE__) && !defined(WITH_HEADLESS) && !defined(WITH_GHOST_SDL) +const char* osx_user_locale(void); +#endif + #ifdef __cplusplus } #endif diff --git a/intern/locale/osx_user_locale.mm b/intern/locale/osx_user_locale.mm new file mode 100644 index 00000000000..1ed33bb1713 --- /dev/null +++ b/intern/locale/osx_user_locale.mm @@ -0,0 +1,22 @@ +#include "boost_locale_wrapper.h" + +#import <Cocoa/Cocoa.h> + +#include <cstdlib> + +static char* user_locale = NULL; + +// get current locale +const char* osx_user_locale() +{ + ::free(user_locale); + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + CFLocaleRef myCFLocale = CFLocaleCopyCurrent(); + NSLocale * myNSLocale = (NSLocale *) myCFLocale; + [myNSLocale autorelease]; + NSString *nsIdentifier = [myNSLocale localeIdentifier]; + user_locale = ::strdup([nsIdentifier UTF8String]); + [pool drain]; + + return user_locale; +} |