kernel32: Better workaround for the lack of locale environment variables on MacOS.
This commit is contained in:
parent
ac227461ac
commit
ed58b1bad0
|
@ -25,6 +25,7 @@
|
||||||
#include "wine/port.h"
|
#include "wine/port.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -506,24 +507,12 @@ static int charset_cmp( const void *name, const void *entry )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* get_env_lcid
|
* get_env_lcid
|
||||||
*/
|
*/
|
||||||
static LCID get_env_lcid( UINT *unix_cp, const char *env_str )
|
static LCID get_env_lcid( UINT *unix_cp, int category )
|
||||||
{
|
{
|
||||||
char *buf, *lang,*country,*charset,*dialect,*next;
|
char *buf, *lang,*country,*charset,*dialect,*next;
|
||||||
LCID ret = 0;
|
LCID ret = 0;
|
||||||
char user_locale[50] = { 0 };
|
|
||||||
#ifdef __APPLE__
|
|
||||||
CFLocaleRef user_locale_ref = CFLocaleCopyCurrent();
|
|
||||||
CFStringRef user_locale_string_ref = CFLocaleGetIdentifier(user_locale_ref);
|
|
||||||
|
|
||||||
CFStringGetCString(user_locale_string_ref, user_locale,
|
if ((lang = setlocale( category, NULL )) && *lang)
|
||||||
sizeof(user_locale), kCFStringEncodingUTF8);
|
|
||||||
CFRelease(user_locale_ref);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (((lang = getenv( "LC_ALL" )) && *lang) ||
|
|
||||||
(env_str && (lang = getenv( env_str )) && *lang) ||
|
|
||||||
((lang = getenv( "LANG" )) && *lang) ||
|
|
||||||
((lang = user_locale) && *lang))
|
|
||||||
{
|
{
|
||||||
if (!strcmp(lang,"POSIX") || !strcmp(lang,"C")) goto done;
|
if (!strcmp(lang,"POSIX") || !strcmp(lang,"C")) goto done;
|
||||||
|
|
||||||
|
@ -560,11 +549,6 @@ static LCID get_env_lcid( UINT *unix_cp, const char *env_str )
|
||||||
else
|
else
|
||||||
FIXME("charset %s was not recognized\n", charset);
|
FIXME("charset %s was not recognized\n", charset);
|
||||||
}
|
}
|
||||||
#ifdef __APPLE__
|
|
||||||
/* charset on Mac OS X is always UTF8 */
|
|
||||||
else if (unix_cp) *unix_cp = CP_UTF8;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lang=next;
|
lang=next;
|
||||||
} while (lang && !ret);
|
} while (lang && !ret);
|
||||||
|
|
||||||
|
@ -2590,13 +2574,28 @@ void LOCALE_Init(void)
|
||||||
UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp = ~0U;
|
UINT ansi_cp = 1252, oem_cp = 437, mac_cp = 10000, unix_cp = ~0U;
|
||||||
LCID lcid;
|
LCID lcid;
|
||||||
|
|
||||||
lcid = get_env_lcid( NULL, NULL );
|
#ifdef __APPLE__
|
||||||
|
/* MacOS doesn't set the locale environment variables so we have to do it ourselves */
|
||||||
|
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 );
|
||||||
|
#endif
|
||||||
|
setlocale( LC_ALL, "" );
|
||||||
|
|
||||||
|
lcid = get_env_lcid( NULL, LC_ALL );
|
||||||
NtSetDefaultLocale( TRUE, lcid );
|
NtSetDefaultLocale( TRUE, lcid );
|
||||||
|
|
||||||
lcid = get_env_lcid( NULL, "LC_MESSAGES" );
|
lcid = get_env_lcid( NULL, LC_MESSAGES );
|
||||||
NtSetDefaultUILanguage( LANGIDFROMLCID(lcid) );
|
NtSetDefaultUILanguage( LANGIDFROMLCID(lcid) );
|
||||||
|
|
||||||
lcid = get_env_lcid( &unix_cp, "LC_CTYPE" );
|
lcid = get_env_lcid( &unix_cp, LC_CTYPE );
|
||||||
NtSetDefaultLocale( FALSE, lcid );
|
NtSetDefaultLocale( FALSE, lcid );
|
||||||
|
|
||||||
ansi_cp = get_lcid_codepage(lcid);
|
ansi_cp = get_lcid_codepage(lcid);
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <locale.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -732,7 +731,6 @@ static BOOL process_init(void)
|
||||||
|
|
||||||
setbuf(stdout,NULL);
|
setbuf(stdout,NULL);
|
||||||
setbuf(stderr,NULL);
|
setbuf(stderr,NULL);
|
||||||
setlocale(LC_CTYPE,"");
|
|
||||||
|
|
||||||
kernel32_handle = GetModuleHandleW(kernel32W);
|
kernel32_handle = GetModuleHandleW(kernel32W);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue