/***************************************************************************** * 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 }
/***************************************************************************** * 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 ); } }
// Because language preferences are set on a per-user basis, we // must get the preferred languages while set to the current // user, before the Apple Installer switches us to root. // So we get the preferred languages here and write them to a // temporary file to be retrieved by our PostInstall app. static void GetPreferredLanguages() { DIR *dirp; struct dirent *dp; char temp[MAXPATHLEN]; char searchPath[MAXPATHLEN]; char savedWD[MAXPATHLEN]; struct stat sbuf; CFMutableArrayRef supportedLanguages; CFStringRef aLanguage; char shortLanguage[32]; CFArrayRef preferredLanguages; int i, j, k; char * language; char *uscore; FILE *f; getcwd(savedWD, sizeof(savedWD)); snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC_payload", tempDirName); callPosixSpawn(temp); snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_payload", tempDirName); mkdir(temp, 0777); chmod(temp, 0777); // Needed because mkdir sets permissions restricted by umask (022) chdir(temp); snprintf(temp, sizeof(temp), "cpio -i -I /tmp/%s/expanded_BOINC.pkg/BOINC.pkg/Payload", tempDirName); callPosixSpawn(temp); chdir(savedWD); // Create an array of all our supported languages supportedLanguages = CFArrayCreateMutable(kCFAllocatorDefault, 100, &kCFTypeArrayCallBacks); aLanguage = CFStringCreateWithCString(NULL, "en", kCFStringEncodingMacRoman); CFArrayAppendValue(supportedLanguages, aLanguage); CFRelease(aLanguage); aLanguage = NULL; dirp = opendir(Catalogs_Dir); if (!dirp) { REPORT_ERROR(true); goto cleanup; } while (true) { dp = readdir(dirp); if (dp == NULL) break; // End of list if (dp->d_name[0] == '.') continue; // Ignore names beginning with '.' strlcpy(searchPath, Catalogs_Dir, sizeof(searchPath)); strlcat(searchPath, dp->d_name, sizeof(searchPath)); strlcat(searchPath, "/", sizeof(searchPath)); strlcat(searchPath, Catalog_Name, sizeof(searchPath)); strlcat(searchPath, ".mo", sizeof(searchPath)); if (stat(searchPath, &sbuf) != 0) continue; // printf("Adding %s to supportedLanguages array\n", dp->d_name); aLanguage = CFStringCreateWithCString(NULL, dp->d_name, kCFStringEncodingMacRoman); CFArrayAppendValue(supportedLanguages, aLanguage); CFRelease(aLanguage); aLanguage = NULL; // If it has a region code ("it_IT") also try without region code ("it") // TODO: Find a more general solution strlcpy(shortLanguage, dp->d_name, sizeof(shortLanguage)); uscore = strchr(shortLanguage, '_'); if (uscore) { *uscore = '\0'; aLanguage = CFStringCreateWithCString(NULL, shortLanguage, kCFStringEncodingMacRoman); CFArrayAppendValue(supportedLanguages, aLanguage); CFRelease(aLanguage); aLanguage = NULL; } } closedir(dirp); // Write a temp file to tell our PostInstall.app our preferred languages snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_preferred_languages", tempDirName); f = fopen(temp, "w"); if (!f) { REPORT_ERROR(true); goto cleanup; } for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) { preferredLanguages = CFBundleCopyLocalizationsForPreferences(supportedLanguages, NULL ); #if 0 // For testing int c = CFArrayGetCount(preferredLanguages); for (k=0; k<c; ++k) { CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, k); printf("Preferred language %u is %s\n", k, CFStringGetCStringPtr(s, kCFStringEncodingMacRoman)); } #endif for (j=0; j<CFArrayGetCount(preferredLanguages); ++j) { aLanguage = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, j); language = (char *)CFStringGetCStringPtr(aLanguage, kCFStringEncodingMacRoman); if (language == NULL) { if (CFStringGetCString(aLanguage, shortLanguage, sizeof(shortLanguage), kCFStringEncodingMacRoman)) { language = shortLanguage; } } if (f && language) { fprintf(f, "%s\n", language); #if CREATE_LOG print_to_log_file("Adding language: %s\n", language); #endif } // Remove all copies of this language from our list of supported languages // so we can get the next preferred language in order of priority for (k=CFArrayGetCount(supportedLanguages)-1; k>=0; --k) { if (CFStringCompare(aLanguage, (CFStringRef)CFArrayGetValueAtIndex(supportedLanguages, k), 0) == kCFCompareEqualTo) { CFArrayRemoveValueAtIndex(supportedLanguages, k); } } // Since the original strings are English, no // further translation is needed for language en. if (language) { if (!strcmp(language, "en")) { fclose(f); CFRelease(preferredLanguages); preferredLanguages = NULL; goto cleanup; } } } CFRelease(preferredLanguages); preferredLanguages = NULL; } if (f) { fprintf(f, "en\n"); fclose(f); } cleanup: CFArrayRemoveAllValues(supportedLanguages); CFRelease(supportedLanguages); supportedLanguages = NULL; #if CREATE_LOG print_to_log_file("Exiting GetPreferredLanguages"); #endif }
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 }