Commit 33bc0156 authored by Felix Paul Kühne's avatar Felix Paul Kühne

* patch by Pierre d'Herbemont which cleans up our locale detection code...

* patch by Pierre d'Herbemont which cleans up our locale detection code heavily and converts it to be CoreFoundation-based only. Thanks!
parent 30bf3ee2
/***************************************************************************** /*****************************************************************************
* darwin_specific.m: Darwin specific features * darwin_specific.m: Darwin specific features
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2004 the VideoLAN team * Copyright (C) 2001-2007 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Sam Hocevar <sam@zoy.org> * Authors: Sam Hocevar <sam@zoy.org>
* Christophe Massiot <massiot@via.ecp.fr> * Christophe Massiot <massiot@via.ecp.fr>
* Pierre d'Herbemont <pdherbemont@free.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -21,69 +22,48 @@ ...@@ -21,69 +22,48 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include <string.h> /* strdup() */ #include <string.h> /* strdup(), strstr() */
#include <stdlib.h> /* free() */ #include <stdlib.h> /* free() */
#include <dirent.h> /* *dir() */
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <Cocoa/Cocoa.h> #include <CoreFoundation/CoreFoundation.h>
#include <CoreFoundation/CFString.h>
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
# include <locale.h> # include <locale.h>
#endif #endif
/***************************************************************************** /* CFLocaleCopyAvailableLocaleIdentifiers is present only on post-10.4 */
* system_Init: fill in program path & retrieve language extern CFArrayRef CFLocaleCopyAvailableLocaleIdentifiers(void) __attribute__((weak_import));
*****************************************************************************/
static int FindLanguage( const char * psz_lang ) /* emulate CFLocaleCopyAvailableLocaleIdentifiers on pre-10.4 */
static CFArrayRef copy_all_locale_indentifiers(void)
{ {
const char ** ppsz_parser; CFMutableArrayRef available_locales;
const char * ppsz_all[] = DIR * dir;
{ struct dirent *file;
"Catalan", "ca",
"Czech", "cs", dir = opendir( "/usr/share/locale" );
"Danish", "da", available_locales = CFArrayCreateMutable( kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks );
"German", "de",
"British", "en_GB", while ( (file = readdir(dir)) )
"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] ) /* we should probably filter out garbage */
|| !strcmp( psz_lang, ppsz_parser[1] ) ) /* we can't use CFStringCreateWithFileSystemRepresentation as it is supported only on post-10.4
{ (and this function is only for pre-10.2) */
setenv( "LANG", ppsz_parser[1], 1 ); CFStringRef locale = CFStringCreateWithCString( kCFAllocatorDefault, file->d_name, kCFStringEncodingUTF8 );
return 1; CFArrayAppendValue( available_locales, (void*)locale );
} CFRelease( locale );
} }
return 0; closedir( dir );
return available_locales;
} }
/*****************************************************************************
* system_Init: fill in program path & retrieve language
*****************************************************************************/
void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
{ {
char i_dummy; char i_dummy;
...@@ -108,24 +88,32 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) ...@@ -108,24 +88,32 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
/* Check if $LANG is set. */ /* Check if $LANG is set. */
if ( (p_char = getenv("LANG")) == NULL ) if ( (p_char = getenv("LANG")) == NULL )
{ {
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; /*
Retrieve the preferred language as chosen in System Preferences.app
/* Retrieve user's preferences. */ (note that CFLocaleCopyCurrent() is not used because it returns the
NSUserDefaults * o_defs = [NSUserDefaults standardUserDefaults]; prefered locale not language)
NSArray * o_languages = [o_defs objectForKey:@"AppleLanguages"]; */
NSEnumerator * o_enumerator = [o_languages objectEnumerator]; CFArrayRef all_locales, preferred_locales;
NSString * o_lang; char psz_locale[50];
while ( (o_lang = [o_enumerator nextObject]) ) if( CFLocaleCopyAvailableLocaleIdentifiers )
all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
else
all_locales = copy_all_locale_indentifiers();
preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );
if ( preferred_locales )
{ {
const char * psz_string = [o_lang lossyCString]; if ( CFArrayGetCount( preferred_locales ) )
if ( FindLanguage( psz_string ) )
{ {
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, 1 );
} }
CFRelease( preferred_locales );
} }
CFRelease( all_locales );
[o_pool release];
} }
vlc_mutex_init( p_this, &p_this->p_libvlc_global->iconv_lock ); vlc_mutex_init( p_this, &p_this->p_libvlc_global->iconv_lock );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment