Index: src/misc/darwin_specific.m =================================================================== --- src/misc/darwin_specific.m (revision 18828) +++ src/misc/darwin_specific.m (working copy) @@ -26,8 +26,8 @@ #include -#include #include +#include #ifdef HAVE_LOCALE_H # include @@ -36,54 +36,6 @@ /***************************************************************************** * system_Init: fill in program path & retrieve language *****************************************************************************/ -static int FindLanguage( const char * psz_lang ) -{ - const char ** ppsz_parser; - const char * ppsz_all[] = - { - "Catalan", "ca", - "Czech", "cs", - "Danish", "da", - "German", "de", - "British", "en_GB", - "English", "en", - "Spanish", "es", - "French", "fr", - "Galician", "gl", - "Hebrew", "he", - "Hungarian", "hu", - "Italian", "it", - "Japanese", "ja", - "Korean", "ko", - "Georgian", "ka", - "Malay", "ms", - "Dutch", "nl", - "Occitan", "oc", - "Brazilian Portuguese", "pt_BR", - "Romanian", "ro", - "Russian", "ru", - "Slovak", "sk", - "Slovenian", "sl", - "Swedish", "sv", - "Turkish", "tr", - "Simplified Chinese", "zh_CN", - "Chinese Traditional", "zh_TW", - NULL - }; - - for( ppsz_parser = ppsz_all ; ppsz_parser[0] ; ppsz_parser += 2 ) - { - if( !strcmp( psz_lang, ppsz_parser[0] ) - || !strcmp( psz_lang, ppsz_parser[1] ) ) - { - setenv( "LANG", ppsz_parser[1], 1 ); - return 1; - } - } - - return 0; -} - void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) { char i_dummy; @@ -108,24 +60,26 @@ /* Check if $LANG is set. */ if ( (p_char = getenv("LANG")) == NULL ) { - NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; + /* + Retrieve the preferred language as chosen in System Preferences.app + (note that CFLocaleCopyCurrent() is not used because it returns the + prefered locale not language) + */ + CFArrayRef all_locales = CFLocaleCopyAvailableLocaleIdentifiers(); + CFArrayRef preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL ); + char psz_locale[50]; - /* Retrieve user's preferences. */ - NSUserDefaults * o_defs = [NSUserDefaults standardUserDefaults]; - NSArray * o_languages = [o_defs objectForKey:@"AppleLanguages"]; - NSEnumerator * o_enumerator = [o_languages objectEnumerator]; - NSString * o_lang; - - while ( (o_lang = [o_enumerator nextObject]) ) + if (preferred_locales) { - const char * psz_string = [o_lang lossyCString]; - if ( FindLanguage( psz_string ) ) + if (CFArrayGetCount( preferred_locales )) { - break; + CFStringRef user_language_string_ref = CFArrayGetValueAtIndex( preferred_locales, 0 ); + CFStringGetCString( user_language_string_ref, psz_locale, sizeof(psz_locale), kCFStringEncodingUTF8 ); + setenv( "LANG", &psz_locale[0], 1 ); } + CFRelease( preferred_locales ); } - - [o_pool release]; + CFRelease( all_locales ); } vlc_mutex_init( p_this, &p_this->p_libvlc_global->iconv_lock );