nsIOS2Locale* os2Converter; nsString xpLocale;
nsCOMPtr<nsIOS2Locale> os2Converter; nsAutoString xpLocale;
nsLocaleService::nsLocaleService(void):	mSystemLocale(nsnull), mApplicationLocale(nsnull){	NS_INIT_REFCNT();#if defined(XP_PC) && !defined(XP_OS2)	nsIWin32Locale*	win32Converter;	nsString		xpLocale;	nsresult result = nsComponentManager::CreateInstance(kWin32LocaleFactoryCID,						NULL,kIWin32LocaleIID,(void**)&win32Converter);	NS_ASSERTION(win32Converter!=NULL,"nsLocaleService: can't get win32 converter\n");	if (NS_SUCCEEDED(result) && win32Converter!=nsnull) {				//		// get the system LCID		//		LCID win_lcid = GetSystemDefaultLCID();		if (win_lcid==0) { win32Converter->Release(); return;}		result = win32Converter->GetXPLocale(win_lcid,&xpLocale);		if (NS_FAILED(result)) { win32Converter->Release(); return;}        PRUnichar* loc = xpLocale.ToNewUnicode();		result = NewLocale(loc, &mSystemLocale);        nsCRT::free(loc);		if (NS_FAILED(result)) { win32Converter->Release(); return;}		//		// get the application LCID		//		win_lcid = GetUserDefaultLCID();		if (win_lcid==0) { win32Converter->Release(); return;}		result = win32Converter->GetXPLocale(win_lcid,&xpLocale);		if (NS_FAILED(result)) { win32Converter->Release(); return;}        loc = xpLocale.ToNewUnicode();		result = NewLocale(loc, &mApplicationLocale);        nsCRT::free(loc);		if (NS_FAILED(result)) { win32Converter->Release(); return;}			win32Converter->Release();	}#endif#if defined(XP_UNIX) || defined(XP_BEOS)    nsIPosixLocale* posixConverter;    nsAutoString xpLocale;    nsresult result = nsComponentManager::CreateInstance(kPosixLocaleFactoryCID,                           NULL,kIPosixLocaleIID,(void**)&posixConverter);    if (NS_SUCCEEDED(result) && posixConverter!=nsnull) {        nsAutoString category;        nsLocale* resultLocale;        int i;        resultLocale = new nsLocale();        if ( resultLocale == NULL ) {             posixConverter->Release();             return;         }        for( i = 0; i < LocaleListLength; i++ ) {            char* lc_temp = nsCRT::strdup(setlocale(posix_locale_category[i],""));            category.AssignWithConversion(LocaleList[i]);            if (lc_temp != nsnull)                result = posixConverter->GetXPLocale(lc_temp,&xpLocale);            else {                char* lang = getenv("LANG");                if ( lang == nsnull ) {                    nsCAutoString langcstr("en-US");	            lang = nsCRT::strdup( langcstr.GetBuffer() );                    result = posixConverter->GetXPLocale(lang,&xpLocale);                    nsCRT::free(lang); 	        }                else                    result = posixConverter->GetXPLocale(lang,&xpLocale);             }            if (NS_FAILED(result)) {                posixConverter->Release();                nsCRT::free(lc_temp);                return;            }            resultLocale->AddCategory(category.GetUnicode(),xpLocale.GetUnicode());            nsCRT::free(lc_temp);        }        (void)resultLocale->QueryInterface(kILocaleIID,(void**)&mSystemLocale);        (void)resultLocale->QueryInterface(kILocaleIID,(void**)&mApplicationLocale);        posixConverter->Release();    }  // if ( NS_SUCCEEDED )...       #endif // XP_UNIX || XP_BEOS#if defined(XP_OS2)    nsIOS2Locale* os2Converter;    nsString xpLocale;    nsresult result = nsComponentManager::CreateInstance(kOS2LocaleFactoryCID,                           NULL,kIOS2LocaleIID,(void**)&os2Converter);    if (NS_SUCCEEDED(result) && os2Converter!=nsnull) {        char* lc_all = nsnull;        char* lang = nsnull;        if (lc_all!=nsnull) {            result = os2Converter->GetXPLocale(lc_all,&xpLocale);            if (NS_FAILED(result)) { os2Converter->Release(); return; }            PRUnichar* loc = xpLocale.ToNewUnicode();            result = NewLocale(loc, &mSystemLocale);            nsCRT::free(loc);            if (NS_FAILED(result)) { os2Converter->Release(); return; }            mApplicationLocale=mSystemLocale;            mApplicationLocale->AddRef();            os2Converter->Release();        } else {            if (lang==nsnull) {                xpLocale.AssignWithConversion("en-US");                PRUnichar* loc = xpLocale.ToNewUnicode();                result = NewLocale(loc, &mSystemLocale);                nsCRT::free(loc);                if (NS_FAILED(result)) { os2Converter->Release(); return; }                mApplicationLocale = mSystemLocale;                mApplicationLocale->AddRef();                os2Converter->Release();            } else {                int i;                nsString category;                nsLocale* resultLocale = new nsLocale();				        if (resultLocale==NULL) { os2Converter->Release(); return; }                for(i=0;i<LocaleListLength;i++) {                // setlocale requires the C runtime                // later down the path the system will be queried for the correct locale                    char* lc_temp = nsnull; // setlocale(os2_locale_category[i],"");                    category.AssignWithConversion(LocaleList[i]);                    if (lc_temp==nsnull) xpLocale.AssignWithConversion("en-US");                    else xpLocale.AssignWithConversion(lc_temp);                    PRUnichar* loc = xpLocale.ToNewUnicode();                    PRUnichar* cat = category.ToNewUnicode();                    resultLocale->AddCategory(cat, loc);                    nsCRT::free(cat);                    nsCRT::free(loc);                                    }                (void)resultLocale->QueryInterface(kILocaleIID,(void**)&mSystemLocale);                (void)resultLocale->QueryInterface(kILocaleIID,(void**)&mApplicationLocale);                os2Converter->Release();            }        }    }#endif // XP_OS2#ifdef XP_MAC	long script = GetScriptManagerVariable(smSysScript);	long lang = GetScriptVariable(smSystemScript,smScriptLang);	long region = GetScriptManagerVariable(smRegionCode);	nsCOMPtr<nsIMacLocale> macConverter;	nsresult result = nsComponentManager::CreateInstance(kMacLocaleFactoryCID,						NULL,kIMacLocaleIID,(void**)getter_AddRefs(macConverter));	if (NS_SUCCEEDED(result) && macConverter!=nsnull) {		nsString xpLocale;		result = macConverter->GetXPLocale((short)script,(short)lang,(short)region,&xpLocale);		if (NS_SUCCEEDED(result)) {			result = NewLocale(xpLocale.GetUnicode(),&mSystemLocale);			if (NS_SUCCEEDED(result)) {				mApplicationLocale = mSystemLocale;				mApplicationLocale->AddRef();			}		}	}#endif}