Пример #1
0
/*****************************************************************************
 * system_Init: fill in program path & retrieve language
 *****************************************************************************/
void system_Init(void)
{
#ifdef ENABLE_NLS
    /* Check if $LANG is set. */
    if( NULL == getenv("LANG") )
    {
        /*
           Retrieve the preferred language as chosen in  System Preferences.app
           (note that CFLocaleCopyCurrent() is not used because it returns the
            preferred locale not language)
        */
        CFArrayRef all_locales, preferred_locales;
        char psz_locale[50];

        all_locales = CFLocaleCopyAvailableLocaleIdentifiers();

        preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );

        if ( preferred_locales )
        {
            if ( CFArrayGetCount( preferred_locales ) )
            {
                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 );
    }
#endif
}
Пример #2
0
/*****************************************************************************
 * system_Init: fill in program path & retrieve language
 *****************************************************************************/
void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
{
    VLC_UNUSED(p_this);
    char i_dummy;
    char *p_char = NULL;
    char *p_oldchar = &i_dummy;
    unsigned int i;
    (void)pi_argc;

    /* Get the full program path and name */
    /* First try to see if we are linked to the framework */
    for (i = 0; i < _dyld_image_count(); i++)
    {
        const char * psz_img_name = _dyld_get_image_name(i);
        /* Check for "VLCKit.framework/Versions/Current/VLCKit",
         * as well as "VLCKit.framework/Versions/A/VLCKit" and
         * "VLC.framework/Versions/B/VLCKit" */
        if( (p_char = strstr( psz_img_name, "VLCKit.framework/Versions/" )) )
        {
            /* Look for the next forward slash */
            p_char += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */
            while( *p_char != '\0' && *p_char != '/')
                p_char++;
            
            /* If the string ends with VLC then we've found a winner */
            if ( !strcmp( p_char, "/VLCKit" ) )
            {
                p_char = strdup( psz_img_name );
                break;
            }
            else
                p_char = NULL;
        }
    }

    if( !p_char )
    {
        char path[MAXPATHLEN+1];
        uint32_t path_len = MAXPATHLEN;
        if ( !_NSGetExecutablePath(path, &path_len) )
            p_char = strdup(path);
    }
    if( !p_char )
    {
        /* We are not linked to the VLC.framework, return the executable path */
        p_char = strdup( ppsz_argv[ 0 ] );
    }

    free(psz_vlcpath);
    psz_vlcpath = p_char;

    /* Remove trailing program name */
    for( ; *p_char ; )
    {
        if( *p_char == '/' )
        {
            *p_oldchar = '/';
            *p_char = '\0';
            p_oldchar = p_char;
        }
        p_char++;
    }

    /* Check if $LANG is set. */
    if( NULL == getenv("LANG") )
    {
        /*
           Retrieve the preferred language as chosen in  System Preferences.app
           (note that CFLocaleCopyCurrent() is not used because it returns the
            preferred locale not language)
        */
        CFArrayRef all_locales, preferred_locales;
        char psz_locale[50];

        all_locales = CFLocaleCopyAvailableLocaleIdentifiers();

        preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );

        if ( preferred_locales )
        {
            if ( CFArrayGetCount( preferred_locales ) )
            {
                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 );
    }
}
static void LOCALE_Init(void)
{
	/*
    extern void __wine_init_codepages( const union cptable *ansi_cp, const union cptable *oem_cp,
                                       const union cptable *unix_cp );
				       */

    // UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp;
    UINT unix_cp = 0;

#ifdef __APPLE__
    /* MacOS doesn't set the locale environment variables so we have to do it ourselves */
    CFArrayRef preferred_locales, all_locales;
    CFStringRef user_language_string_ref = NULL;
    char user_locale[50];

    CFLocaleRef user_locale_ref = CFLocaleCopyCurrent();
    CFStringRef user_locale_string_ref = CFLocaleGetIdentifier( user_locale_ref );

    CFStringGetCString( user_locale_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 );
    CFRelease( user_locale_ref );
    if (!strchr( user_locale, '.' )) strcat( user_locale, ".UTF-8" );
    unix_cp = CP_UTF8;  /* default to utf-8 even if we don't get a valid locale */
    setenv( "LANG", user_locale, 0 );
    // TRACE( "setting locale to '%s'\n", user_locale );

    /* We still want to set the retrieve the preferred language as chosen in
       System Preferences.app, because it can differ from CFLocaleCopyCurrent().
    */
    all_locales = CFLocaleCopyAvailableLocaleIdentifiers();
    preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL );
    if (preferred_locales && CFArrayGetCount( preferred_locales ))
        user_language_string_ref = CFArrayGetValueAtIndex( preferred_locales, 0 );
    CFRelease( all_locales );
#endif /* __APPLE__ */

    // FIXME setlocale( LC_ALL, "" );

    unix_cp = setup_unix_locales();
    if (!lcid_LC_MESSAGES) lcid_LC_MESSAGES = lcid_LC_CTYPE;
#if 0
#ifdef __APPLE__
    /* Override lcid_LC_MESSAGES with user_language if LC_MESSAGES is set to default */
    if (lcid_LC_MESSAGES == lcid_LC_CTYPE && user_language_string_ref)
    {
        struct locale_name locale_name;
        WCHAR buffer[128];
        CFStringGetCString( user_language_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 );
        strcpynAtoW( buffer, user_locale, sizeof(buffer)/sizeof(WCHAR) );
        parse_locale_name( buffer, &locale_name );
        lcid_LC_MESSAGES = locale_name.lcid;
        TRACE( "setting lcid_LC_MESSAGES to '%s'\n", user_locale );
    }
    if (preferred_locales)
        CFRelease( preferred_locales );
#endif

    NtSetDefaultUILanguage( LANGIDFROMLCID(lcid_LC_MESSAGES) );
    NtSetDefaultLocale( TRUE, lcid_LC_MESSAGES );
    NtSetDefaultLocale( FALSE, lcid_LC_CTYPE );

    ansi_cp = get_lcid_codepage( LOCALE_USER_DEFAULT );
    GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
                    (LPWSTR)&mac_cp, sizeof(mac_cp)/sizeof(WCHAR) );
    GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
                    (LPWSTR)&oem_cp, sizeof(oem_cp)/sizeof(WCHAR) );
    if (!unix_cp)
        GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IDEFAULTUNIXCODEPAGE | LOCALE_RETURN_NUMBER,
                        (LPWSTR)&unix_cp, sizeof(unix_cp)/sizeof(WCHAR) );

    if (!(ansi_cptable = wine_cp_get_table( ansi_cp )))
        ansi_cptable = wine_cp_get_table( 1252 );
    if (!(oem_cptable = wine_cp_get_table( oem_cp )))
        oem_cptable  = wine_cp_get_table( 437 );
    if (!(mac_cptable = wine_cp_get_table( mac_cp )))
        mac_cptable  = wine_cp_get_table( 10000 );
    if (unix_cp != CP_UTF8)
    {
        if (!(unix_cptable = wine_cp_get_table( unix_cp )))
            unix_cptable  = wine_cp_get_table( 28591 );
    }

    __wine_init_codepages( ansi_cptable, oem_cptable, unix_cptable );

    TRACE( "ansi=%03d oem=%03d mac=%03d unix=%03d\n",
           ansi_cptable->info.codepage, oem_cptable->info.codepage,
           mac_cptable->info.codepage, unix_cp );

    setlocale(LC_NUMERIC, "C");  /* FIXME: oleaut32 depends on this */
#endif
}