bug 195093 : modernize nsILocale (r=smontagu, sr=darin)
git-svn-id: svn://10.0.0.236/trunk@148538 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -160,7 +160,7 @@
|
||||
|
||||
var bundleURL = "chrome://calendar/locale/dateFormat.properties";
|
||||
var dateBundle = stringBundleService.createBundle(
|
||||
bundleURL, localeService.GetApplicationLocale()
|
||||
bundleURL, localeService.getApplicationLocale()
|
||||
);
|
||||
|
||||
// Reset the headers
|
||||
|
||||
@@ -88,7 +88,7 @@ nsresult txResultStringComparator::init(const nsAFlatString& aLanguage)
|
||||
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
if (!aLanguage.IsEmpty()) {
|
||||
rv = localeService->NewLocale(aLanguage.get(),
|
||||
rv = localeService->NewLocale(aLanguage,
|
||||
getter_AddRefs(locale));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -52,5 +52,5 @@
|
||||
[scriptable, uuid(21035ee0-4556-11d3-91cd-00105aa3f7dc)]
|
||||
interface nsILocale : nsISupports {
|
||||
|
||||
wstring GetCategory (in wstring category);
|
||||
AString getCategory (in AString category);
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
[scriptable, uuid(7c094410-4558-11d3-91cd-00105aa3f7dc)]
|
||||
interface nsILocaleDefinition : nsISupports {
|
||||
void SetLocaleCategory(in wstring category, in wstring value);
|
||||
void setLocaleCategory(in AString category, in AString value);
|
||||
};
|
||||
|
||||
// The Locale service interface. This is a singleton object, and should be
|
||||
@@ -49,12 +49,12 @@ interface nsILocaleDefinition : nsISupports {
|
||||
[scriptable, uuid(48ab1fa0-4550-11d3-91cd-00105aa3f7dc)]
|
||||
interface nsILocaleService : nsISupports {
|
||||
|
||||
nsILocale NewLocale(in wstring aLocale);
|
||||
nsILocale NewLocaleObject(in nsILocaleDefinition localeDefinition);
|
||||
nsILocale GetSystemLocale();
|
||||
nsILocale GetApplicationLocale();
|
||||
nsILocale GetLocaleFromAcceptLanguage(in string acceptLanguage);
|
||||
wstring GetLocaleComponentForUserAgent();
|
||||
nsILocale newLocale(in AString aLocale);
|
||||
nsILocale newLocaleObject(in nsILocaleDefinition localeDefinition);
|
||||
nsILocale getSystemLocale();
|
||||
nsILocale getApplicationLocale();
|
||||
nsILocale getLocaleFromAcceptLanguage(in string acceptLanguage);
|
||||
AString getLocaleComponentForUserAgent();
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
@@ -45,18 +45,20 @@
|
||||
#include <Script.h>
|
||||
|
||||
// {E58B24B2-FD1A-11d2-9E8E-0060089FE59B}
|
||||
#define NS_IMACLOCALE_IID \
|
||||
{ 0xe58b24b2, 0xfd1a, 0x11d2, \
|
||||
{ 0x9e, 0x8e, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
#define NS_IMACLOCALE_IID \
|
||||
{ 0xe58b24b2, 0xfd1a, 0x11d2, \
|
||||
{ 0x9e, 0x8e, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
|
||||
|
||||
class nsIMacLocale : public nsISupports {
|
||||
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMACLOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale,short* scriptCode,short* langCode, short* regionCode) = 0;
|
||||
NS_IMETHOD GetXPLocale(short scriptCode,short langCode, short regionCode, nsString* locale) = 0;
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMACLOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale, short* scriptCode,
|
||||
short* langCode, short* regionCode) = 0;
|
||||
NS_IMETHOD GetXPLocale(short scriptCode, short langCode, short regionCode,
|
||||
nsAString& locale) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class nsIOS2Locale : public nsISupports
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IOS2LOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(PRUnichar* os2Locale,size_t length)=0;
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsString* locale)=0;
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsAString& locale)=0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -60,8 +60,8 @@ class nsIPosixLocale : public nsISupports {
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPOSIXLOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale, nsACString& posixLocale) = 0;
|
||||
NS_IMETHOD GetXPLocale(const char* posixLocale, nsString* locale)=0;
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale, nsACString& posixLocale) = 0;
|
||||
NS_IMETHOD GetXPLocale(const char* posixLocale, nsAString& locale) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -45,21 +45,17 @@
|
||||
#include <windows.h>
|
||||
|
||||
// {D92D57C2-BA1D-11d2-AF0C-0060089FE59B}
|
||||
#define NS_IWIN32LOCALE_IID \
|
||||
{ 0xd92d57c2, 0xba1d, 0x11d2, \
|
||||
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
#define NS_IWIN32LOCALE_IID \
|
||||
{ 0xd92d57c2, 0xba1d, 0x11d2, \
|
||||
{ 0xaf, 0xc, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
|
||||
|
||||
|
||||
class nsIWin32Locale : public nsISupports {
|
||||
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWIN32LOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale,LCID* winLCID) = 0;
|
||||
NS_IMETHOD GetXPLocale(LCID winLCID,nsString* locale) = 0;
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWIN32LOCALE_IID)
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale, LCID* winLCID) = 0;
|
||||
NS_IMETHOD GetXPLocale(LCID winLCID, nsAString& locale) = 0;
|
||||
};
|
||||
|
||||
nsresult GetPlatformLocale(const PRUnichar* localeValue, LCID* winLCID);
|
||||
nsresult GetXPLocale(LCID winLCID, PRUnichar* localeValue);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -150,34 +150,31 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
|
||||
// locale -> script code + charset name
|
||||
m_scriptcode = smRoman;
|
||||
|
||||
PRUnichar *aLocaleUnichar;
|
||||
nsAutoString aCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"));
|
||||
nsAutoString localeStr;
|
||||
|
||||
// get locale string, use app default if no locale specified
|
||||
if (locale == nsnull) {
|
||||
nsCOMPtr<nsILocaleService> localeService =
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsILocale *appLocale;
|
||||
res = localeService->GetApplicationLocale(&appLocale);
|
||||
nsCOMPtr<nsILocale> appLocale;
|
||||
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = appLocale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
appLocale->Release();
|
||||
res = appLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"),
|
||||
localeStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"),
|
||||
localeStr);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsAutoString aLocale(aLocaleUnichar);
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
|
||||
short scriptcode, langcode, regioncode;
|
||||
nsCOMPtr <nsIMacLocale> macLocale = do_GetService(NS_MACLOCALE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
if (NS_SUCCEEDED(res = macLocale->GetPlatformLocale(&aLocale, &scriptcode, &langcode, ®ioncode))) {
|
||||
if (NS_SUCCEEDED(res = macLocale->GetPlatformLocale(localeStr, &scriptcode, &langcode, ®ioncode))) {
|
||||
m_scriptcode = scriptcode;
|
||||
}
|
||||
}
|
||||
@@ -185,7 +182,7 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsCAutoString mappedCharset;
|
||||
res = platformCharset->GetDefaultCharsetForLocale(aLocale.get(), mappedCharset);
|
||||
res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = mCollation->SetCharset(mappedCharset.get());
|
||||
}
|
||||
|
||||
@@ -90,13 +90,10 @@ nsresult nsCollationMacUC::ConvertLocale(
|
||||
NS_ENSURE_ARG_POINTER(aNSLocale);
|
||||
NS_ENSURE_ARG_POINTER(aMacLocale);
|
||||
|
||||
nsXPIDLString aLocaleString;
|
||||
nsresult res = aNSLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE").get(), getter_Copies(aLocaleString));
|
||||
if (res != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
NS_ENSURE_ARG_POINTER(aLocaleString.get());
|
||||
nsCAutoString tmp;
|
||||
tmp.AssignWithConversion(aLocaleString);
|
||||
nsAutoString localeString;
|
||||
nsresult res = aNSLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), localeString);
|
||||
NS_ENSURE_TRUE(res == noErr && !localeString.IsEmpty(), NS_ERROR_FAILURE);
|
||||
NS_LossyConvertUTF16toASCII tmp(localeString);
|
||||
tmp.ReplaceChar('-', '_');
|
||||
OSStatus err;
|
||||
err = ::LocaleRefFromLocaleString( tmp.get(), aMacLocale);
|
||||
|
||||
@@ -235,27 +235,25 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatMac, nsIDateTimeFormat)
|
||||
|
||||
nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
|
||||
{
|
||||
PRUnichar *aLocaleUnichar = NULL;
|
||||
nsString aCategory(NS_LITERAL_STRING("NSILOCALE_TIME"));
|
||||
nsAutoString localeStr;
|
||||
nsAutoString category(NS_LITERAL_STRING("NSILOCALE_TIME"));
|
||||
nsresult res;
|
||||
|
||||
// use cached info if match with stored locale
|
||||
if (NULL == locale) {
|
||||
if (mLocale.Length() &&
|
||||
if (nsnull == locale) {
|
||||
if (!mLocale.IsEmpty() &&
|
||||
mLocale.Equals(mAppLocale, nsCaseInsensitiveStringComparator())) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
res = locale->GetCategory(category, localeStr);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
if (!mLocale.IsEmpty() &&
|
||||
mLocale.Equals(aLocaleUnichar,
|
||||
mLocale.Equals(localeStr,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
return NS_OK;
|
||||
}
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,41 +267,38 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
|
||||
nsCOMPtr<nsILocaleService> localeService =
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsILocale *appLocale;
|
||||
res = localeService->GetApplicationLocale(&appLocale);
|
||||
nsCOMPtr<nsILocale> appLocale;
|
||||
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = appLocale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
mAppLocale.Assign(aLocaleUnichar); // cache app locale name
|
||||
res = appLocale->GetCategory(category, localeStr);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
mAppLocale = localeStr; // cache app locale name
|
||||
}
|
||||
appLocale->Release();
|
||||
}
|
||||
}
|
||||
|
||||
// use app default if no locale specified
|
||||
if (NULL == locale) {
|
||||
if (nsnull == locale) {
|
||||
mUseDefaultLocale = true;
|
||||
}
|
||||
else {
|
||||
mUseDefaultLocale = false;
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
res = locale->GetCategory(category, localeStr);
|
||||
}
|
||||
|
||||
// Get a script code and charset name from locale, if available
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
mLocale.Assign(aLocaleUnichar); // cache locale name
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && !loceleStr.IsEmpty()) {
|
||||
mLocale.Assign(localeStr); // cache locale name
|
||||
|
||||
nsCOMPtr <nsIMacLocale> macLocale = do_GetService(NS_MACLOCALE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = macLocale->GetPlatformLocale(&mLocale, &mScriptcode, &mLangcode, &mRegioncode);
|
||||
res = macLocale->GetPlatformLocale(mLocale, &mScriptcode, &mLangcode, &mRegioncode);
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsCAutoString mappedCharset;
|
||||
res = platformCharset->GetDefaultCharsetForLocale(mLocale.get(), mappedCharset);
|
||||
res = platformCharset->GetDefaultCharsetForLocale(mLocale, mappedCharset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mCharset = mappedCharset;
|
||||
}
|
||||
|
||||
@@ -45,175 +45,176 @@
|
||||
#include "nsLocaleCID.h"
|
||||
#include "prprf.h"
|
||||
#include <Script.h>
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
struct iso_lang_map
|
||||
{
|
||||
char* iso_code;
|
||||
short mac_lang_code;
|
||||
short mac_script_code;
|
||||
char* iso_code;
|
||||
short mac_lang_code;
|
||||
short mac_script_code;
|
||||
|
||||
};
|
||||
typedef struct iso_lang_map iso_lang_map;
|
||||
|
||||
const iso_lang_map lang_list[] = {
|
||||
{ "sq", langAlbanian, smRoman },
|
||||
{ "am", langAmharic, smEthiopic },
|
||||
{ "ar", langArabic, smArabic },
|
||||
{ "hy", langArmenian, smArmenian},
|
||||
{ "as", langAssamese, smBengali },
|
||||
{ "ay", langAymara, smRoman},
|
||||
{ "eu", langBasque, smRoman},
|
||||
{ "bn", langBengali, smBengali },
|
||||
{ "dz", langDzongkha, smTibetan },
|
||||
{ "br", langBreton, smRoman },
|
||||
{ "bg", langBulgarian, smCyrillic },
|
||||
{ "my", langBurmese, smBurmese },
|
||||
{ "km", langKhmer, smKhmer },
|
||||
{ "ca", langCatalan, smRoman },
|
||||
{ "zh", langTradChinese, smTradChinese },
|
||||
{ "hr", langCroatian, smRoman },
|
||||
{ "cs", langCzech, smCentralEuroRoman },
|
||||
{ "da", langDanish, smRoman },
|
||||
{ "nl", langDutch, smRoman },
|
||||
{ "en", langEnglish, smRoman },
|
||||
{ "eo", langEsperanto, smRoman },
|
||||
{ "et", langEstonian, smCentralEuroRoman},
|
||||
{ "fo", langFaeroese, smRoman },
|
||||
{ "fa", langFarsi, smArabic },
|
||||
{ "fi", langFinnish, smRoman },
|
||||
{ "fr", langFrench, smRoman },
|
||||
{ "ka", langGeorgian, smGeorgian },
|
||||
{ "de", langGerman, smRoman },
|
||||
{ "el", langGreek, smGreek },
|
||||
{ "gn", langGuarani, smRoman },
|
||||
{ "gu", langGujarati, smGujarati },
|
||||
{ "he", langHebrew, smHebrew },
|
||||
{ "iw", langHebrew, smHebrew },
|
||||
{ "hu", langHungarian, smCentralEuroRoman },
|
||||
{ "is", langIcelandic, smRoman },
|
||||
{ "in", langIndonesian, smRoman },
|
||||
{ "id", langIndonesian, smRoman },
|
||||
{ "iu", langInuktitut, smEthiopic },
|
||||
{ "ga", langIrish, smRoman },
|
||||
{ "it", langItalian, smRoman },
|
||||
{ "ja", langJapanese, smJapanese },
|
||||
{ "jw", langJavaneseRom, smRoman },
|
||||
{ "kn", langKannada, smKannada },
|
||||
{ "ks", langKashmiri, smArabic },
|
||||
{ "kk", langKazakh, smCyrillic },
|
||||
{ "ky", langKirghiz, smCyrillic },
|
||||
{ "ko", langKorean, smKorean },
|
||||
{ "ku", langKurdish, smArabic },
|
||||
{ "lo", langLao, smLao },
|
||||
{ "la", langLatin, smRoman },
|
||||
{ "lv", langLatvian, smCentralEuroRoman },
|
||||
{ "lt", langLithuanian, smCentralEuroRoman },
|
||||
{ "mk", langMacedonian, smCyrillic },
|
||||
{ "mg", langMalagasy, smRoman },
|
||||
{ "ml", langMalayalam, smMalayalam },
|
||||
{ "mt", langMaltese, smRoman },
|
||||
{ "mr", langMarathi, smDevanagari },
|
||||
{ "mo", langMoldavian, smCyrillic },
|
||||
{ "ne", langNepali, smDevanagari },
|
||||
{ "no", langNorwegian, smRoman },
|
||||
{ "or", langOriya, smOriya },
|
||||
{ "om", langOromo, smEthiopic },
|
||||
{ "ps", langPashto, smArabic },
|
||||
{ "pl", langPolish, smCentralEuroRoman },
|
||||
{ "pt", langPortuguese, smRoman },
|
||||
{ "pa", langPunjabi, smGurmukhi },
|
||||
{ "ro", langRomanian, smRoman },
|
||||
{ "ru", langRussian, smCyrillic },
|
||||
{ "sa", langSanskrit, smDevanagari },
|
||||
{ "sr", langSerbian, smCyrillic },
|
||||
{ "sd", langSindhi, smArabic },
|
||||
{ "si", langSinhalese, smSinhalese },
|
||||
{ "sk", langSlovak, smCentralEuroRoman },
|
||||
{ "sl", langSlovenian, smRoman },
|
||||
{ "so", langSomali, smRoman },
|
||||
{ "es", langSpanish, smRoman },
|
||||
{ "su", langSundaneseRom, smRoman },
|
||||
{ "sw", langSwahili, smRoman },
|
||||
{ "sv", langSwedish, smRoman },
|
||||
{ "tl", langTagalog, smRoman },
|
||||
{ "tg", langTajiki, smCyrillic },
|
||||
{ "ta", langTamil, smTamil },
|
||||
{ "tt", langTatar, smCyrillic },
|
||||
{ "te", langTelugu, smTelugu },
|
||||
{ "th", langThai, smThai },
|
||||
{ "bo", langTibetan, smTibetan },
|
||||
{ "ti", langTigrinya, smEthiopic },
|
||||
{ "tr", langTurkish, smRoman },
|
||||
{ "tk", langTurkmen, smCyrillic },
|
||||
{ "ug", langUighur, smCyrillic },
|
||||
{ "uk", langUkrainian, smCyrillic },
|
||||
{ "ur", langUrdu, smArabic },
|
||||
{ "uz", langUzbek, smCyrillic },
|
||||
{ "vi", langVietnamese, smVietnamese },
|
||||
{ "cy", langWelsh, smRoman },
|
||||
{ "ji", langYiddish, smHebrew },
|
||||
{ "yi", langYiddish, smHebrew },
|
||||
{ "", 0, 0}
|
||||
{ "sq", langAlbanian, smRoman },
|
||||
{ "am", langAmharic, smEthiopic },
|
||||
{ "ar", langArabic, smArabic },
|
||||
{ "hy", langArmenian, smArmenian},
|
||||
{ "as", langAssamese, smBengali },
|
||||
{ "ay", langAymara, smRoman},
|
||||
{ "eu", langBasque, smRoman},
|
||||
{ "bn", langBengali, smBengali },
|
||||
{ "dz", langDzongkha, smTibetan },
|
||||
{ "br", langBreton, smRoman },
|
||||
{ "bg", langBulgarian, smCyrillic },
|
||||
{ "my", langBurmese, smBurmese },
|
||||
{ "km", langKhmer, smKhmer },
|
||||
{ "ca", langCatalan, smRoman },
|
||||
{ "zh", langTradChinese, smTradChinese },
|
||||
{ "hr", langCroatian, smRoman },
|
||||
{ "cs", langCzech, smCentralEuroRoman },
|
||||
{ "da", langDanish, smRoman },
|
||||
{ "nl", langDutch, smRoman },
|
||||
{ "en", langEnglish, smRoman },
|
||||
{ "eo", langEsperanto, smRoman },
|
||||
{ "et", langEstonian, smCentralEuroRoman},
|
||||
{ "fo", langFaeroese, smRoman },
|
||||
{ "fa", langFarsi, smArabic },
|
||||
{ "fi", langFinnish, smRoman },
|
||||
{ "fr", langFrench, smRoman },
|
||||
{ "ka", langGeorgian, smGeorgian },
|
||||
{ "de", langGerman, smRoman },
|
||||
{ "el", langGreek, smGreek },
|
||||
{ "gn", langGuarani, smRoman },
|
||||
{ "gu", langGujarati, smGujarati },
|
||||
{ "he", langHebrew, smHebrew },
|
||||
{ "iw", langHebrew, smHebrew },
|
||||
{ "hu", langHungarian, smCentralEuroRoman },
|
||||
{ "is", langIcelandic, smRoman },
|
||||
{ "in", langIndonesian, smRoman },
|
||||
{ "id", langIndonesian, smRoman },
|
||||
{ "iu", langInuktitut, smEthiopic },
|
||||
{ "ga", langIrish, smRoman },
|
||||
{ "it", langItalian, smRoman },
|
||||
{ "ja", langJapanese, smJapanese },
|
||||
{ "jw", langJavaneseRom, smRoman },
|
||||
{ "kn", langKannada, smKannada },
|
||||
{ "ks", langKashmiri, smArabic },
|
||||
{ "kk", langKazakh, smCyrillic },
|
||||
{ "ky", langKirghiz, smCyrillic },
|
||||
{ "ko", langKorean, smKorean },
|
||||
{ "ku", langKurdish, smArabic },
|
||||
{ "lo", langLao, smLao },
|
||||
{ "la", langLatin, smRoman },
|
||||
{ "lv", langLatvian, smCentralEuroRoman },
|
||||
{ "lt", langLithuanian, smCentralEuroRoman },
|
||||
{ "mk", langMacedonian, smCyrillic },
|
||||
{ "mg", langMalagasy, smRoman },
|
||||
{ "ml", langMalayalam, smMalayalam },
|
||||
{ "mt", langMaltese, smRoman },
|
||||
{ "mr", langMarathi, smDevanagari },
|
||||
{ "mo", langMoldavian, smCyrillic },
|
||||
{ "ne", langNepali, smDevanagari },
|
||||
{ "no", langNorwegian, smRoman },
|
||||
{ "or", langOriya, smOriya },
|
||||
{ "om", langOromo, smEthiopic },
|
||||
{ "ps", langPashto, smArabic },
|
||||
{ "pl", langPolish, smCentralEuroRoman },
|
||||
{ "pt", langPortuguese, smRoman },
|
||||
{ "pa", langPunjabi, smGurmukhi },
|
||||
{ "ro", langRomanian, smRoman },
|
||||
{ "ru", langRussian, smCyrillic },
|
||||
{ "sa", langSanskrit, smDevanagari },
|
||||
{ "sr", langSerbian, smCyrillic },
|
||||
{ "sd", langSindhi, smArabic },
|
||||
{ "si", langSinhalese, smSinhalese },
|
||||
{ "sk", langSlovak, smCentralEuroRoman },
|
||||
{ "sl", langSlovenian, smRoman },
|
||||
{ "so", langSomali, smRoman },
|
||||
{ "es", langSpanish, smRoman },
|
||||
{ "su", langSundaneseRom, smRoman },
|
||||
{ "sw", langSwahili, smRoman },
|
||||
{ "sv", langSwedish, smRoman },
|
||||
{ "tl", langTagalog, smRoman },
|
||||
{ "tg", langTajiki, smCyrillic },
|
||||
{ "ta", langTamil, smTamil },
|
||||
{ "tt", langTatar, smCyrillic },
|
||||
{ "te", langTelugu, smTelugu },
|
||||
{ "th", langThai, smThai },
|
||||
{ "bo", langTibetan, smTibetan },
|
||||
{ "ti", langTigrinya, smEthiopic },
|
||||
{ "tr", langTurkish, smRoman },
|
||||
{ "tk", langTurkmen, smCyrillic },
|
||||
{ "ug", langUighur, smCyrillic },
|
||||
{ "uk", langUkrainian, smCyrillic },
|
||||
{ "ur", langUrdu, smArabic },
|
||||
{ "uz", langUzbek, smCyrillic },
|
||||
{ "vi", langVietnamese, smVietnamese },
|
||||
{ "cy", langWelsh, smRoman },
|
||||
{ "ji", langYiddish, smHebrew },
|
||||
{ "yi", langYiddish, smHebrew },
|
||||
{ nsnull, 0, 0}
|
||||
};
|
||||
|
||||
struct iso_country_map
|
||||
{
|
||||
char* iso_code;
|
||||
short mac_region_code;
|
||||
char* iso_code;
|
||||
short mac_region_code;
|
||||
};
|
||||
|
||||
typedef struct iso_country_map iso_country_map;
|
||||
|
||||
const iso_country_map country_list[] = {
|
||||
{ "US", verUS},
|
||||
{ "EG", verArabic},
|
||||
{ "DZ", verArabic},
|
||||
{ "AU", verAustralia},
|
||||
{ "BE", verFrBelgium },
|
||||
{ "CA", verEngCanada },
|
||||
{ "CN", verChina },
|
||||
{ "HR", verYugoCroatian },
|
||||
{ "CY", verCyprus },
|
||||
{ "DK", verDenmark },
|
||||
{ "EE", verEstonia },
|
||||
{ "FI", verFinland },
|
||||
{ "FR", verFrance },
|
||||
{ "DE", verGermany },
|
||||
{ "EL", verGreece },
|
||||
{ "HU", verHungary },
|
||||
{ "IS", verIceland },
|
||||
{ "IN", verIndiaHindi},
|
||||
{ "IR", verIran },
|
||||
{ "IQ", verArabic },
|
||||
{ "IE", verIreland },
|
||||
{ "IL", verIsrael },
|
||||
{ "IT", verItaly },
|
||||
{ "JP", verJapan },
|
||||
{ "KP", verKorea },
|
||||
{ "LV", verLatvia },
|
||||
{ "LY", verArabic },
|
||||
{ "LT", verLithuania },
|
||||
{ "LU", verFrBelgiumLux },
|
||||
{ "MT", verMalta },
|
||||
{ "MA", verArabic },
|
||||
{ "NL", verNetherlands },
|
||||
{ "NO", verNorway },
|
||||
{ "PK", verPakistan },
|
||||
{ "PL", verPoland },
|
||||
{ "PT", verPortugal },
|
||||
{ "RU", verRussia },
|
||||
{ "SA", verArabic },
|
||||
{ "ES", verSpain },
|
||||
{ "SE", verSweden },
|
||||
{ "CH", verFrSwiss },
|
||||
{ "TW", verTaiwan},
|
||||
{ "TH", verThailand },
|
||||
{ "TN", verArabic},
|
||||
{ "TR", verTurkey },
|
||||
{ "GB", verBritain },
|
||||
{ "", 0 }
|
||||
{ "US", verUS},
|
||||
{ "EG", verArabic},
|
||||
{ "DZ", verArabic},
|
||||
{ "AU", verAustralia},
|
||||
{ "BE", verFrBelgium },
|
||||
{ "CA", verEngCanada },
|
||||
{ "CN", verChina },
|
||||
{ "HR", verYugoCroatian },
|
||||
{ "CY", verCyprus },
|
||||
{ "DK", verDenmark },
|
||||
{ "EE", verEstonia },
|
||||
{ "FI", verFinland },
|
||||
{ "FR", verFrance },
|
||||
{ "DE", verGermany },
|
||||
{ "EL", verGreece },
|
||||
{ "HU", verHungary },
|
||||
{ "IS", verIceland },
|
||||
{ "IN", verIndiaHindi},
|
||||
{ "IR", verIran },
|
||||
{ "IQ", verArabic },
|
||||
{ "IE", verIreland },
|
||||
{ "IL", verIsrael },
|
||||
{ "IT", verItaly },
|
||||
{ "JP", verJapan },
|
||||
{ "KP", verKorea },
|
||||
{ "LV", verLatvia },
|
||||
{ "LY", verArabic },
|
||||
{ "LT", verLithuania },
|
||||
{ "LU", verFrBelgiumLux },
|
||||
{ "MT", verMalta },
|
||||
{ "MA", verArabic },
|
||||
{ "NL", verNetherlands },
|
||||
{ "NO", verNorway },
|
||||
{ "PK", verPakistan },
|
||||
{ "PL", verPoland },
|
||||
{ "PT", verPortugal },
|
||||
{ "RU", verRussia },
|
||||
{ "SA", verArabic },
|
||||
{ "ES", verSpain },
|
||||
{ "SE", verSweden },
|
||||
{ "CH", verFrSwiss },
|
||||
{ "TW", verTaiwan},
|
||||
{ "TH", verThailand },
|
||||
{ "TN", verArabic},
|
||||
{ "TR", verTurkey },
|
||||
{ "GB", verBritain },
|
||||
{ nsnull, 0 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* nsMacLocale ISupports */
|
||||
NS_IMPL_ISUPPORTS1(nsMacLocale,nsIMacLocale)
|
||||
@@ -228,93 +229,89 @@ nsMacLocale::~nsMacLocale(void)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacLocale::GetPlatformLocale(const nsString* locale,short* scriptCode, short* langCode, short* regionCode)
|
||||
nsMacLocale::GetPlatformLocale(const nsAString& locale, short* scriptCode, short* langCode, short* regionCode)
|
||||
{
|
||||
char country_code[3];
|
||||
char lang_code[3];
|
||||
char region_code[3];
|
||||
char* xp_locale = ToNewCString(*locale);
|
||||
bool validCountryFound;
|
||||
int i;
|
||||
|
||||
if (xp_locale != nsnull) {
|
||||
if (!ParseLocaleString(xp_locale,lang_code,country_code,region_code,'-')) {
|
||||
*scriptCode = smRoman;
|
||||
*langCode = langEnglish;
|
||||
*regionCode = verUS;
|
||||
delete [] xp_locale;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (country_code[0]!=0)
|
||||
{
|
||||
validCountryFound=false;
|
||||
for(i=0;strlen(country_list[i].iso_code)!=0;i++) {
|
||||
if (strcmp(country_list[i].iso_code,country_code)==0) {
|
||||
*regionCode = country_list[i].mac_region_code;
|
||||
validCountryFound=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!validCountryFound) {
|
||||
*scriptCode = smRoman;
|
||||
*langCode = langEnglish;
|
||||
*regionCode = verUS;
|
||||
delete [] xp_locale;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;strlen(lang_list[i].iso_code)!=0;i++) {
|
||||
if (strcmp(lang_list[i].iso_code,lang_code)==0) {
|
||||
*scriptCode = lang_list[i].mac_script_code;
|
||||
*langCode = lang_list[i].mac_lang_code;
|
||||
delete [] xp_locale;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
char country_code[3];
|
||||
char lang_code[3];
|
||||
char region_code[3];
|
||||
bool validCountryFound;
|
||||
int i;
|
||||
|
||||
if (!ParseLocaleString(NS_LossyConvertUTF16toASCII(locale).get(), lang_code, country_code, region_code, '-')) {
|
||||
*scriptCode = smRoman;
|
||||
*langCode = langEnglish;
|
||||
*regionCode = verUS;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (country_code[0]!=0)
|
||||
{
|
||||
validCountryFound=false;
|
||||
for(i=0;country_list[i].iso_code;i++) {
|
||||
if (strcmp(country_list[i].iso_code,country_code)==0) {
|
||||
*regionCode = country_list[i].mac_region_code;
|
||||
validCountryFound=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!validCountryFound) {
|
||||
*scriptCode = smRoman;
|
||||
*langCode = langEnglish;
|
||||
*regionCode = verUS;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;lang_list[i].iso_code;i++) {
|
||||
if (strcmp(lang_list[i].iso_code, lang_code)==0) {
|
||||
*scriptCode = lang_list[i].mac_script_code;
|
||||
*langCode = lang_list[i].mac_lang_code;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacLocale::GetXPLocale(short scriptCode, short langCode, short regionCode, nsString* locale)
|
||||
nsMacLocale::GetXPLocale(short scriptCode, short langCode, short regionCode, nsAString& locale)
|
||||
{
|
||||
|
||||
int i;
|
||||
bool validResultFound = false;
|
||||
nsString temp;
|
||||
|
||||
//
|
||||
// parse language
|
||||
//
|
||||
for(i=0;strlen(lang_list[i].iso_code)!=0;i++) {
|
||||
if (langCode==lang_list[i].mac_lang_code && scriptCode==lang_list[i].mac_script_code) {
|
||||
temp.AssignWithConversion(lang_list[i].iso_code);
|
||||
validResultFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// parse region
|
||||
//
|
||||
for(i=0;strlen(country_list[i].iso_code)!=0;i++) {
|
||||
if (regionCode==country_list[i].mac_region_code) {
|
||||
temp.Append(PRUnichar('-'));
|
||||
temp.AppendWithConversion(country_list[i].iso_code);
|
||||
validResultFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (validResultFound) {
|
||||
*locale = temp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
int i;
|
||||
bool validResultFound = false;
|
||||
|
||||
locale.Truncate();
|
||||
|
||||
//
|
||||
// parse language
|
||||
//
|
||||
for(i=0;lang_list[i].iso_code;i++) {
|
||||
if (langCode==lang_list[i].mac_lang_code && scriptCode==lang_list[i].mac_script_code) {
|
||||
CopyASCIItoUTF16(nsDependentCString(lang_list[i].iso_code), locale);
|
||||
validResultFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validResultFound) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
//
|
||||
// parse region
|
||||
//
|
||||
for(i=0;country_list[i].iso_code;i++) {
|
||||
if (regionCode==country_list[i].mac_region_code) {
|
||||
locale.Append(PRUnichar('-'));
|
||||
// XXX : perhaps, we need AppendASCIItoUTF16
|
||||
AppendUTF8toUTF16(nsDependentCString(country_list[i].iso_code), locale);
|
||||
validResultFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (validResultFound) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
}
|
||||
|
||||
@@ -323,41 +320,41 @@ nsMacLocale::GetXPLocale(short scriptCode, short langCode, short regionCode, nsS
|
||||
PRBool
|
||||
nsMacLocale::ParseLocaleString(const char* locale_string, char* language, char* country, char* region, char separator)
|
||||
{
|
||||
size_t len;
|
||||
size_t len;
|
||||
|
||||
len = strlen(locale_string);
|
||||
if (len==0 || (len!=2 && len!=5 && len!=8))
|
||||
return PR_FALSE;
|
||||
|
||||
if (len==2) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=0;
|
||||
region[0]=0;
|
||||
} else if (len==5) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=locale_string[3];
|
||||
country[1]=locale_string[4];
|
||||
country[2]=0;
|
||||
region[0]=0;
|
||||
if (locale_string[2]!=separator) return PR_FALSE;
|
||||
} else if (len==8) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=locale_string[3];
|
||||
country[1]=locale_string[4];
|
||||
country[2]=0;
|
||||
region[0]=locale_string[6];
|
||||
region[1]=locale_string[7];
|
||||
region[2]=0;
|
||||
if (locale_string[2]!=separator || locale_string[5]!=separator) return PR_FALSE;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
len = strlen(locale_string);
|
||||
if (len==0 || (len!=2 && len!=5 && len!=8))
|
||||
return PR_FALSE;
|
||||
|
||||
if (len==2) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=0;
|
||||
region[0]=0;
|
||||
} else if (len==5) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=locale_string[3];
|
||||
country[1]=locale_string[4];
|
||||
country[2]=0;
|
||||
region[0]=0;
|
||||
if (locale_string[2]!=separator) return PR_FALSE;
|
||||
} else if (len==8) {
|
||||
language[0]=locale_string[0];
|
||||
language[1]=locale_string[1];
|
||||
language[2]=0;
|
||||
country[0]=locale_string[3];
|
||||
country[1]=locale_string[4];
|
||||
country[2]=0;
|
||||
region[0]=locale_string[6];
|
||||
region[1]=locale_string[7];
|
||||
region[2]=0;
|
||||
if (locale_string[2]!=separator || locale_string[5]!=separator) return PR_FALSE;
|
||||
} else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
nsMacLocale();
|
||||
virtual ~nsMacLocale();
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale,short* scriptCode, short* langCode, short* regionCode);
|
||||
NS_IMETHOD GetXPLocale(short scriptCode, short langCode, short regionCode, nsString* locale);
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale,short* scriptCode, short* langCode, short* regionCode);
|
||||
NS_IMETHOD GetXPLocale(short scriptCode, short langCode, short regionCode, nsAString& locale);
|
||||
|
||||
protected:
|
||||
inline PRBool ParseLocaleString(const char* locale_string, char* language, char* country, char* region, char separator);
|
||||
|
||||
@@ -300,11 +300,11 @@ nsLanguageAtomService::GetLocaleLanguageGroup(nsIAtom** aResult)
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsAutoString category;
|
||||
category.AssignWithConversion(NSILOCALE_MESSAGE);
|
||||
nsXPIDLString loc;
|
||||
res = locale->GetCategory(category.get(), getter_Copies(loc));
|
||||
nsAutoString loc;
|
||||
res = locale->GetCategory(category, loc);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsCOMPtr<nsILanguageAtom> langAtom;
|
||||
res = LookupLanguage(loc, getter_AddRefs(langAtom));
|
||||
res = LookupLanguage(loc.get(), getter_AddRefs(langAtom));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = langAtom->GetLanguageGroup(getter_AddRefs(mLocaleLangGroup));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
@@ -45,190 +45,168 @@
|
||||
#include "nsLocale.h"
|
||||
#include "nsLocaleCID.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#define LOCALE_HASH_SIZE 0xFF
|
||||
#define LOCALE_HASH_SIZE 0xFF
|
||||
|
||||
|
||||
/* nsILocale */
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocale, nsILocale)
|
||||
|
||||
nsLocale::nsLocale(void)
|
||||
: fHashtable(nsnull), fCategoryCount(0)
|
||||
: fHashtable(nsnull), fCategoryCount(0)
|
||||
{
|
||||
fHashtable = PL_NewHashTable(LOCALE_HASH_SIZE,&nsLocale::Hash_HashFunction,
|
||||
&nsLocale::Hash_CompareNSString,&nsLocale::Hash_CompareNSString,NULL,NULL);
|
||||
NS_ASSERTION(fHashtable!=NULL,"nsLocale: failed to allocate PR_Hashtable");
|
||||
fHashtable = PL_NewHashTable(LOCALE_HASH_SIZE,&nsLocale::Hash_HashFunction,
|
||||
&nsLocale::Hash_CompareNSString,
|
||||
&nsLocale::Hash_CompareNSString, NULL, NULL);
|
||||
NS_ASSERTION(fHashtable, "nsLocale: failed to allocate PR_Hashtable");
|
||||
}
|
||||
|
||||
nsLocale::nsLocale(nsLocale* other)
|
||||
: fHashtable(nsnull), fCategoryCount(0)
|
||||
nsLocale::nsLocale(nsLocale* other) : fHashtable(nsnull), fCategoryCount(0)
|
||||
{
|
||||
fHashtable = PL_NewHashTable(LOCALE_HASH_SIZE,&nsLocale::Hash_HashFunction,
|
||||
&nsLocale::Hash_CompareNSString,&nsLocale::Hash_CompareNSString,NULL,NULL);
|
||||
NS_ASSERTION(fHashtable!=NULL,"nsLocale: failed to allocate PR_Hashtable");
|
||||
fHashtable = PL_NewHashTable(LOCALE_HASH_SIZE,&nsLocale::Hash_HashFunction,
|
||||
&nsLocale::Hash_CompareNSString,
|
||||
&nsLocale::Hash_CompareNSString, NULL, NULL);
|
||||
NS_ASSERTION(fHashtable, "nsLocale: failed to allocate PR_Hashtable");
|
||||
|
||||
//
|
||||
// enumerate Hash and copy
|
||||
//
|
||||
PL_HashTableEnumerateEntries(other->fHashtable,&nsLocale::Hash_EnumerateCopy,fHashtable);
|
||||
//
|
||||
// enumerate Hash and copy
|
||||
//
|
||||
PL_HashTableEnumerateEntries(other->fHashtable,
|
||||
&nsLocale::Hash_EnumerateCopy, fHashtable);
|
||||
}
|
||||
|
||||
|
||||
nsLocale::nsLocale(nsString** categoryList,nsString** valueList, PRUint32 count)
|
||||
: fHashtable(NULL),
|
||||
fCategoryCount(0)
|
||||
nsLocale::nsLocale(const nsStringArray& categoryList,
|
||||
const nsStringArray& valueList)
|
||||
: fHashtable(NULL), fCategoryCount(0)
|
||||
{
|
||||
PRInt32 i;
|
||||
PRUnichar* key, *value;
|
||||
|
||||
PRUint32 i;
|
||||
nsString* key, *value;
|
||||
fHashtable = PL_NewHashTable(LOCALE_HASH_SIZE,&nsLocale::Hash_HashFunction,
|
||||
&nsLocale::Hash_CompareNSString,
|
||||
&nsLocale::Hash_CompareNSString,
|
||||
NULL, NULL);
|
||||
NS_ASSERTION(fHashtable, "nsLocale: failed to allocate PR_Hashtable");
|
||||
|
||||
fHashtable = PL_NewHashTable(LOCALE_HASH_SIZE,&nsLocale::Hash_HashFunction,
|
||||
&nsLocale::Hash_CompareNSString,&nsLocale::Hash_CompareNSString,NULL,NULL);
|
||||
NS_ASSERTION(fHashtable!=NULL,"nsLocale: failed to allocate PR_Hashtable");
|
||||
|
||||
if (fHashtable!=NULL)
|
||||
{
|
||||
for(i=0;i<count;i++)
|
||||
{
|
||||
key = new nsString(*categoryList[i]);
|
||||
NS_ASSERTION(key!=NULL,"nsLocale: failed to allocate internal hash key");
|
||||
value = new nsString(*valueList[i]);
|
||||
NS_ASSERTION(value!=NULL,"nsLocale: failed to allocate internal hash value");
|
||||
(void)PL_HashTableAdd(fHashtable,key,value);
|
||||
}
|
||||
}
|
||||
|
||||
if (fHashtable)
|
||||
{
|
||||
for(i=0; i < categoryList.Count(); ++i)
|
||||
{
|
||||
key = ToNewUnicode(*categoryList.StringAt(i));
|
||||
NS_ASSERTION(key, "nsLocale: failed to allocate internal hash key");
|
||||
value = ToNewUnicode(*valueList.StringAt(i));
|
||||
NS_ASSERTION(value, "nsLocale: failed to allocate internal hash value");
|
||||
if (!PL_HashTableAdd(fHashtable,key,value)) {
|
||||
nsMemory::Free(key);
|
||||
nsMemory::Free(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsLocale::~nsLocale(void)
|
||||
{
|
||||
{
|
||||
// enumerate all the entries with a delete function to
|
||||
// safely delete all the keys and values
|
||||
PL_HashTableEnumerateEntries(fHashtable, &nsLocale::Hash_EnumerateDelete,
|
||||
NULL);
|
||||
|
||||
// enumerate all the entries with a delete function to
|
||||
// safely delete all the keys and values
|
||||
PL_HashTableEnumerateEntries(fHashtable,&nsLocale::Hash_EnmerateDelete,NULL);
|
||||
|
||||
PL_HashTableDestroy(fHashtable);
|
||||
|
||||
PL_HashTableDestroy(fHashtable);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocale::GetCategory(const nsString* category,nsString* result)
|
||||
nsLocale::GetCategory(const nsAString& category, nsAString& result)
|
||||
{
|
||||
const PRUnichar *value = (const PRUnichar*)
|
||||
PL_HashTableLookup(fHashtable, PromiseFlatString(category).get());
|
||||
|
||||
const nsString* value;
|
||||
|
||||
value = (const nsString*)PL_HashTableLookup(fHashtable,category);
|
||||
if (value!=NULL)
|
||||
{
|
||||
(*result)=(*value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocale::GetCategory(const PRUnichar *category,PRUnichar **result)
|
||||
{
|
||||
|
||||
nsString aCategory(category);
|
||||
const nsString* value;
|
||||
|
||||
value = (const nsString*)PL_HashTableLookup(fHashtable,&aCategory);
|
||||
if (value!=NULL)
|
||||
{
|
||||
(*result) = ToNewUnicode(*value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
if (value)
|
||||
{
|
||||
result.Assign(value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocale::AddCategory(const PRUnichar *category, const PRUnichar *value)
|
||||
nsLocale::AddCategory(const nsAString &category, const nsAString &value)
|
||||
{
|
||||
nsString* new_key = new nsString(category);
|
||||
if (!new_key) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsString* new_value = new nsString(value);
|
||||
if (!new_value) return NS_ERROR_OUT_OF_MEMORY;
|
||||
PRUnichar* newKey = ToNewUnicode(category);
|
||||
if (!newKey)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
(void)PL_HashTableAdd(fHashtable,new_key,new_value);
|
||||
PRUnichar* newValue = ToNewUnicode(value);
|
||||
if (!newValue) {
|
||||
nsMemory::Free(newKey);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
if (!PL_HashTableAdd(fHashtable, newKey, newValue)) {
|
||||
nsMemory::Free(newKey);
|
||||
nsMemory::Free(newValue);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PLHashNumber
|
||||
nsLocale::Hash_HashFunction(const void* key)
|
||||
{
|
||||
const nsString* stringKey;
|
||||
PLHashNumber hash;
|
||||
PRInt32 length;
|
||||
const PRUnichar* ptr = (const PRUnichar *) key;
|
||||
PLHashNumber hash;
|
||||
|
||||
stringKey = (const nsString*)key;
|
||||
hash = (PLHashNumber)0;
|
||||
|
||||
hash = (PLHashNumber)0;
|
||||
length = stringKey->Length();
|
||||
while (*ptr)
|
||||
hash += (PLHashNumber) *ptr++;
|
||||
|
||||
for(length-=1;length>=0;length--)
|
||||
hash += (PLHashNumber)stringKey->CharAt(length);
|
||||
|
||||
return hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
PRIntn
|
||||
nsLocale::Hash_CompareNSString(const void* s1, const void* s2)
|
||||
{
|
||||
const nsString* string1;
|
||||
const nsString* string2;
|
||||
|
||||
string1 = (const nsString*)s1;
|
||||
string2 = (const nsString*)s2;
|
||||
|
||||
return string1->Equals(*string2);
|
||||
return !nsCRT::strcmp((const PRUnichar *) s1, (const PRUnichar *) s2);
|
||||
}
|
||||
|
||||
|
||||
PRIntn
|
||||
nsLocale::Hash_EnmerateDelete(PLHashEntry *he, PRIntn hashIndex, void *arg)
|
||||
nsLocale::Hash_EnumerateDelete(PLHashEntry *he, PRIntn hashIndex, void *arg)
|
||||
{
|
||||
nsString* key, *value;
|
||||
// delete an entry
|
||||
nsMemory::Free((PRUnichar *)he->key);
|
||||
nsMemory::Free((PRUnichar *)he->value);
|
||||
|
||||
key = (nsString*)he->key;
|
||||
value = (nsString*)he->value;
|
||||
|
||||
// delete the keys
|
||||
delete key;
|
||||
delete value;
|
||||
|
||||
|
||||
return (HT_ENUMERATE_NEXT | HT_ENUMERATE_REMOVE);
|
||||
return (HT_ENUMERATE_NEXT | HT_ENUMERATE_REMOVE);
|
||||
}
|
||||
|
||||
PRIntn
|
||||
nsLocale::Hash_EnumerateCopy(PLHashEntry *he, PRIntn hashIndex, void* arg)
|
||||
{
|
||||
nsString *new_key, *new_value;
|
||||
PRUnichar* newKey = ToNewUnicode(nsDependentString((PRUnichar *)he->key));
|
||||
if (!newKey)
|
||||
return HT_ENUMERATE_STOP;
|
||||
|
||||
new_key = new nsString(*((nsString*)he->key));
|
||||
if (!new_key)
|
||||
return HT_ENUMERATE_STOP;
|
||||
PRUnichar* newValue = ToNewUnicode(nsDependentString((PRUnichar *)he->value));
|
||||
if (!newValue) {
|
||||
nsMemory::Free(newKey);
|
||||
return HT_ENUMERATE_STOP;
|
||||
}
|
||||
|
||||
new_value = new nsString(*((nsString*)he->value));
|
||||
if (!new_value)
|
||||
return HT_ENUMERATE_STOP;
|
||||
if (!PL_HashTableAdd((PLHashTable*)arg, newKey, newValue)) {
|
||||
nsMemory::Free(newKey);
|
||||
nsMemory::Free(newValue);
|
||||
return HT_ENUMERATE_STOP;
|
||||
}
|
||||
|
||||
(void)PL_HashTableAdd((PLHashTable*)arg,new_key,new_value);
|
||||
|
||||
return (HT_ENUMERATE_NEXT);
|
||||
return (HT_ENUMERATE_NEXT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#include "nsILocale.h"
|
||||
#include "plhash.h"
|
||||
|
||||
class nsStringArray;
|
||||
|
||||
class nsLocale : public nsILocale {
|
||||
friend class nsLocaleDefinition;
|
||||
friend class nsLocaleService;
|
||||
@@ -46,22 +48,20 @@ class nsLocale : public nsILocale {
|
||||
|
||||
public:
|
||||
nsLocale(void);
|
||||
nsLocale(nsString** categoryList,nsString** valueList, PRUint32 count);
|
||||
nsLocale(const nsStringArray& categoryList, const nsStringArray& valueList);
|
||||
nsLocale(nsLocale* other);
|
||||
virtual ~nsLocale(void);
|
||||
|
||||
NS_IMETHOD GetCategory(const nsString* category, nsString* result);
|
||||
|
||||
/* Declare methods from nsILocale */
|
||||
NS_DECL_NSILOCALE
|
||||
/* Declare methods from nsILocale */
|
||||
NS_DECL_NSILOCALE
|
||||
|
||||
protected:
|
||||
|
||||
NS_IMETHOD AddCategory(const PRUnichar* category, const PRUnichar* value);
|
||||
NS_IMETHOD AddCategory(const nsAString& category, const nsAString& value);
|
||||
|
||||
static PLHashNumber PR_CALLBACK Hash_HashFunction(const void* key);
|
||||
static PRIntn PR_CALLBACK Hash_CompareNSString(const void* s1, const void* s2);
|
||||
static PRIntn PR_CALLBACK Hash_EnmerateDelete(PLHashEntry *he, PRIntn hashIndex, void *arg);
|
||||
static PRIntn PR_CALLBACK Hash_EnumerateDelete(PLHashEntry *he, PRIntn hashIndex, void *arg);
|
||||
static PRIntn PR_CALLBACK Hash_EnumerateCopy(PLHashEntry *he, PRIntn hashIndex, void *arg);
|
||||
|
||||
PLHashTable* fHashtable;
|
||||
|
||||
@@ -120,8 +120,8 @@ protected:
|
||||
nsresult SetSystemLocale(void);
|
||||
nsresult SetApplicationLocale(void);
|
||||
|
||||
nsILocale* mSystemLocale;
|
||||
nsILocale* mApplicationLocale;
|
||||
nsCOMPtr<nsILocale> mSystemLocale;
|
||||
nsCOMPtr<nsILocale> mApplicationLocale;
|
||||
|
||||
};
|
||||
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
//
|
||||
// nsILocaleDefintion
|
||||
//
|
||||
NS_IMETHOD SetLocaleCategory(const PRUnichar *category, const PRUnichar *value);
|
||||
NS_IMETHOD SetLocaleCategory(const nsAString &category, const nsAString &value);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -157,46 +157,44 @@ protected:
|
||||
//
|
||||
// nsLocaleService methods
|
||||
//
|
||||
nsLocaleService::nsLocaleService(void)
|
||||
: mSystemLocale(nsnull), mApplicationLocale(nsnull)
|
||||
nsLocaleService::nsLocaleService(void)
|
||||
: mSystemLocale(0), mApplicationLocale(0)
|
||||
{
|
||||
#if defined(XP_WIN)
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIWin32Locale> win32Converter
|
||||
= do_CreateInstance(NS_WIN32LOCALE_CONTRACTID, &result);
|
||||
nsCOMPtr<nsIWin32Locale> win32Converter = do_CreateInstance(NS_WIN32LOCALE_CONTRACTID);
|
||||
|
||||
nsString xpLocale;
|
||||
NS_ASSERTION(win32Converter!=NULL,"nsLocaleService: can't get win32 converter\n");
|
||||
if (NS_SUCCEEDED(result) && win32Converter) {
|
||||
|
||||
//
|
||||
// get the system LCID
|
||||
//
|
||||
LCID win_lcid = GetSystemDefaultLCID();
|
||||
if (win_lcid==0) { return;}
|
||||
result = win32Converter->GetXPLocale(win_lcid,&xpLocale);
|
||||
if (NS_FAILED(result)) { return;}
|
||||
result = NewLocale(xpLocale.get(), &mSystemLocale);
|
||||
if (NS_FAILED(result)) { return;}
|
||||
NS_ASSERTION(win32Converter, "nsLocaleService: can't get win32 converter\n");
|
||||
|
||||
//
|
||||
// get the application LCID
|
||||
//
|
||||
win_lcid = GetUserDefaultLCID();
|
||||
if (win_lcid==0) { return;}
|
||||
result = win32Converter->GetXPLocale(win_lcid,&xpLocale);
|
||||
if (NS_FAILED(result)) { return;}
|
||||
result = NewLocale(xpLocale.get(), &mApplicationLocale);
|
||||
if (NS_FAILED(result)) { return;}
|
||||
}
|
||||
nsAutoString xpLocale;
|
||||
if (win32Converter) {
|
||||
|
||||
nsresult result;
|
||||
//
|
||||
// get the system LCID
|
||||
//
|
||||
LCID win_lcid = GetSystemDefaultLCID();
|
||||
if (win_lcid==0) { return;}
|
||||
result = win32Converter->GetXPLocale(win_lcid, xpLocale);
|
||||
if (NS_FAILED(result)) { return;}
|
||||
result = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
|
||||
if (NS_FAILED(result)) { return;}
|
||||
|
||||
//
|
||||
// get the application LCID
|
||||
//
|
||||
win_lcid = GetUserDefaultLCID();
|
||||
if (win_lcid==0) { return;}
|
||||
result = win32Converter->GetXPLocale(win_lcid, xpLocale);
|
||||
if (NS_FAILED(result)) { return;}
|
||||
result = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale));
|
||||
if (NS_FAILED(result)) { return;}
|
||||
}
|
||||
#endif
|
||||
#if (defined(XP_UNIX) || defined(XP_BEOS)) && !defined(XP_MACOSX)
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPosixLocale> posixConverter =
|
||||
do_CreateInstance(NS_POSIXLOCALE_CONTRACTID, &result);
|
||||
nsCOMPtr<nsIPosixLocale> posixConverter = do_CreateInstance(NS_POSIXLOCALE_CONTRACTID);
|
||||
|
||||
nsAutoString xpLocale, platformLocale;
|
||||
if (NS_SUCCEEDED(result) && posixConverter) {
|
||||
if (posixConverter) {
|
||||
nsAutoString category, category_platform;
|
||||
nsLocale* resultLocale;
|
||||
int i;
|
||||
@@ -206,46 +204,40 @@ nsLocaleService::nsLocaleService(void)
|
||||
return;
|
||||
}
|
||||
for( i = 0; i < LocaleListLength; i++ ) {
|
||||
char* lc_temp = nsCRT::strdup(setlocale(posix_locale_category[i],""));
|
||||
nsresult result;
|
||||
char* lc_temp = setlocale(posix_locale_category[i], "");
|
||||
category.AssignWithConversion(LocaleList[i]);
|
||||
category_platform.AssignWithConversion(LocaleList[i]);
|
||||
category_platform.Append(NS_LITERAL_STRING("##PLATFORM"));
|
||||
if (lc_temp != nsnull) {
|
||||
result = posixConverter->GetXPLocale(lc_temp,&xpLocale);
|
||||
result = posixConverter->GetXPLocale(lc_temp, xpLocale);
|
||||
platformLocale.AssignWithConversion(lc_temp);
|
||||
} else {
|
||||
char* lang = getenv("LANG");
|
||||
if ( lang == nsnull ) {
|
||||
nsCAutoString langcstr("en-US");
|
||||
platformLocale.Assign(NS_LITERAL_STRING("en_US"));
|
||||
lang = ToNewCString(langcstr);
|
||||
result = posixConverter->GetXPLocale(lang,&xpLocale);
|
||||
nsCRT::free(lang);
|
||||
}
|
||||
result = posixConverter->GetXPLocale("eu-US", xpLocale);
|
||||
}
|
||||
else {
|
||||
result = posixConverter->GetXPLocale(lang,&xpLocale);
|
||||
result = posixConverter->GetXPLocale(lang, xpLocale);
|
||||
platformLocale.AssignWithConversion(lang);
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(result)) {
|
||||
nsCRT::free(lc_temp);
|
||||
return;
|
||||
}
|
||||
resultLocale->AddCategory(category.get(),xpLocale.get());
|
||||
resultLocale->AddCategory(category_platform.get(),platformLocale.get());
|
||||
nsCRT::free(lc_temp);
|
||||
resultLocale->AddCategory(category, xpLocale);
|
||||
resultLocale->AddCategory(category_platform, platformLocale);
|
||||
}
|
||||
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mSystemLocale);
|
||||
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mApplicationLocale);
|
||||
mSystemLocale = do_QueryInterface(resultLocale);
|
||||
mApplicationLocale = do_QueryInterface(resultLocale);
|
||||
} // if ( NS_SUCCEEDED )...
|
||||
|
||||
#endif // XP_UNIX || XP_BEOS
|
||||
#if defined(XP_OS2)
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIOS2Locale> os2Converter
|
||||
= do_CreateInstance(NS_OS2LOCALE_CONTRACTID, &result);
|
||||
nsCOMPtr<nsIOS2Locale> os2Converter = do_CreateInstance(NS_OS2LOCALE_CONTRACTID);
|
||||
nsAutoString xpLocale;
|
||||
if (NS_SUCCEEDED(result) && os2Converter) {
|
||||
if (os2Converter) {
|
||||
nsAutoString category;
|
||||
nsLocale* resultLocale;
|
||||
int i;
|
||||
@@ -270,30 +262,28 @@ nsLocaleService::nsLocaleService(void)
|
||||
UNI_MBS_STRING_POINTER,
|
||||
(void **)&lc_temp);
|
||||
category.AssignWithConversion(LocaleList[i]);
|
||||
nsresult result;
|
||||
if (lc_temp != nsnull)
|
||||
result = os2Converter->GetXPLocale(lc_temp,&xpLocale);
|
||||
result = os2Converter->GetXPLocale(lc_temp, xpLocale);
|
||||
else {
|
||||
char* lang = getenv("LANG");
|
||||
if ( lang == nsnull ) {
|
||||
nsCAutoString langcstr("en-US");
|
||||
lang = ToNewCString(langcstr);
|
||||
result = os2Converter->GetXPLocale(lang,&xpLocale);
|
||||
nsCRT::free(lang);
|
||||
}
|
||||
result = os2Converter->GetXPLocale("en-US", xpLocale);
|
||||
}
|
||||
else
|
||||
result = os2Converter->GetXPLocale(lang,&xpLocale);
|
||||
result = os2Converter->GetXPLocale(lang, xpLocale);
|
||||
}
|
||||
if (NS_FAILED(result)) {
|
||||
UniFreeMem(lc_temp);
|
||||
UniFreeLocaleObject(locale_object);
|
||||
return;
|
||||
}
|
||||
resultLocale->AddCategory(category.get(),xpLocale.get());
|
||||
resultLocale->AddCategory(category, xpLocale);
|
||||
UniFreeMem(lc_temp);
|
||||
}
|
||||
UniFreeLocaleObject(locale_object);
|
||||
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mSystemLocale);
|
||||
(void)resultLocale->QueryInterface(NS_GET_IID(nsILocale),(void**)&mApplicationLocale);
|
||||
mSystemLocale = do_QueryInterface(resultLocale);
|
||||
mApplicationLocale = do_QueryInterface(resultLocale);
|
||||
} // if ( NS_SUCCEEDED )...
|
||||
|
||||
#endif
|
||||
@@ -302,17 +292,15 @@ nsLocaleService::nsLocaleService(void)
|
||||
long script = GetScriptManagerVariable(smSysScript);
|
||||
long lang = GetScriptVariable(smSystemScript,smScriptLang);
|
||||
long region = GetScriptManagerVariable(smRegionCode);
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIMacLocale> macConverter
|
||||
= do_CreateInstance(NS_MACLOCALE_CONTRACTID, &result);
|
||||
if (NS_SUCCEEDED(result) && macConverter) {
|
||||
nsString xpLocale;
|
||||
result = macConverter->GetXPLocale((short)script,(short)lang,(short)region,&xpLocale);
|
||||
nsCOMPtr<nsIMacLocale> macConverter = do_CreateInstance(NS_MACLOCALE_CONTRACTID);
|
||||
if (macConverter) {
|
||||
nsresult result;
|
||||
nsAutoString xpLocale;
|
||||
result = macConverter->GetXPLocale((short)script,(short)lang,(short)region, xpLocale);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = NewLocale(xpLocale.get(),&mSystemLocale);
|
||||
result = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
mApplicationLocale = mSystemLocale;
|
||||
mApplicationLocale->AddRef();
|
||||
NS_ADDREF(mApplicationLocale = mSystemLocale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,14 +309,12 @@ nsLocaleService::nsLocaleService(void)
|
||||
|
||||
nsLocaleService::~nsLocaleService(void)
|
||||
{
|
||||
if (mSystemLocale) mSystemLocale->Release();
|
||||
if (mApplicationLocale) mApplicationLocale->Release();
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsLocaleService, nsILocaleService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocaleService::NewLocale(const PRUnichar *aLocale, nsILocale **_retval)
|
||||
nsLocaleService::NewLocale(const nsAString &aLocale, nsILocale **_retval)
|
||||
{
|
||||
int i;
|
||||
nsresult result;
|
||||
@@ -340,7 +326,7 @@ nsLocaleService::NewLocale(const PRUnichar *aLocale, nsILocale **_retval)
|
||||
|
||||
for(i=0;i<LocaleListLength;i++) {
|
||||
nsString category; category.AssignWithConversion(LocaleList[i]);
|
||||
result = resultLocale->AddCategory(category.get(),aLocale);
|
||||
result = resultLocale->AddCategory(category, aLocale);
|
||||
if (NS_FAILED(result)) { delete resultLocale; return result;}
|
||||
}
|
||||
|
||||
@@ -364,8 +350,7 @@ NS_IMETHODIMP
|
||||
nsLocaleService::GetSystemLocale(nsILocale **_retval)
|
||||
{
|
||||
if (mSystemLocale) {
|
||||
mSystemLocale->AddRef();
|
||||
*_retval = mSystemLocale;
|
||||
NS_ADDREF(*_retval = mSystemLocale);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -377,8 +362,7 @@ NS_IMETHODIMP
|
||||
nsLocaleService::GetApplicationLocale(nsILocale **_retval)
|
||||
{
|
||||
if (mApplicationLocale) {
|
||||
mApplicationLocale->AddRef();
|
||||
*_retval = mApplicationLocale;
|
||||
NS_ADDREF(*_retval = mApplicationLocale);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -480,7 +464,7 @@ nsLocaleService::GetLocaleFromAcceptLanguage(const char *acceptLanguage, nsILoca
|
||||
//
|
||||
result = NS_ERROR_FAILURE;
|
||||
if (countLang>0) {
|
||||
result = NewLocale(NS_ConvertASCIItoUCS2(acceptLanguageList[0]).get(),_retval);
|
||||
result = NewLocale(NS_ConvertASCIItoUTF16(acceptLanguageList[0]), _retval);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -492,20 +476,20 @@ nsLocaleService::GetLocaleFromAcceptLanguage(const char *acceptLanguage, nsILoca
|
||||
|
||||
|
||||
nsresult
|
||||
nsLocaleService::GetLocaleComponentForUserAgent(PRUnichar **_retval)
|
||||
nsLocaleService::GetLocaleComponentForUserAgent(nsAString& retval)
|
||||
{
|
||||
nsCOMPtr<nsILocale> system_locale;
|
||||
nsresult result;
|
||||
nsCOMPtr<nsILocale> system_locale;
|
||||
nsresult result;
|
||||
|
||||
result = GetSystemLocale(getter_AddRefs(system_locale));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsString lc_messages; lc_messages.AssignWithConversion(NSILOCALE_MESSAGE);
|
||||
result = system_locale->GetCategory(lc_messages.get(),_retval);
|
||||
return result;
|
||||
}
|
||||
result = GetSystemLocale(getter_AddRefs(system_locale));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = system_locale->
|
||||
GetCategory(NS_LITERAL_STRING(NSILOCALE_MESSAGE), retval);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -543,7 +527,7 @@ nsLocaleDefinition::~nsLocaleDefinition(void)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLocaleDefinition::SetLocaleCategory(const PRUnichar *category, const PRUnichar *value)
|
||||
nsLocaleDefinition::SetLocaleCategory(const nsAString &category, const nsAString &value)
|
||||
{
|
||||
if (mLocaleDefinition)
|
||||
return mLocaleDefinition->AddCategory(category,value);
|
||||
|
||||
@@ -103,25 +103,22 @@ NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime(
|
||||
PRInt32 second,
|
||||
PRUnichar **dateTimeString)
|
||||
{
|
||||
nsILocale* aLocale;
|
||||
nsString localeName(locale);
|
||||
nsCOMPtr<nsILocale> aLocale;
|
||||
nsresult rv;
|
||||
|
||||
*dateTimeString = NULL;
|
||||
|
||||
|
||||
// get locale service
|
||||
nsCOMPtr<nsILocaleService> localeService =
|
||||
do_GetService(kLocaleServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = localeName.Length() ? localeService->NewLocale(localeName.get(), &aLocale) :
|
||||
localeService->GetApplicationLocale(&aLocale);
|
||||
rv = (locale && *locale) ?
|
||||
localeService->NewLocale(nsDependentString(locale), getter_AddRefs(aLocale)) :
|
||||
localeService->GetApplicationLocale(getter_AddRefs(aLocale));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && aLocale) {
|
||||
nsIDateTimeFormat *aDateTimeFormat;
|
||||
rv = nsComponentManager::CreateInstance(kDateTimeFormatCID, NULL,
|
||||
NS_GET_IID(nsIDateTimeFormat), (void **) &aDateTimeFormat);
|
||||
if (NS_SUCCEEDED(rv) && aDateTimeFormat) {
|
||||
nsCOMPtr<nsIDateTimeFormat> aDateTimeFormat = do_CreateInstance(kDateTimeFormatCID);
|
||||
|
||||
if (aDateTimeFormat) {
|
||||
struct tm tmTime;
|
||||
time_t timetTime;
|
||||
|
||||
@@ -158,9 +155,7 @@ NS_IMETHODIMP nsScriptableDateFormat::FormatDateTime(
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(aDateTimeFormat);
|
||||
}
|
||||
NS_RELEASE(aLocale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ nsOS2Locale::GetPlatformLocale(PRUnichar* os2Locale, size_t length)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOS2Locale::GetXPLocale(const char* os2Locale, nsString* locale)
|
||||
nsOS2Locale::GetXPLocale(const char* os2Locale, nsAString& locale)
|
||||
{
|
||||
char country_code[3];
|
||||
char lang_code[3];
|
||||
@@ -89,12 +89,12 @@ nsOS2Locale::GetXPLocale(const char* os2Locale, nsString* locale)
|
||||
|
||||
if (os2Locale!=nsnull) {
|
||||
if (strcmp(os2Locale,"C")==0 || strcmp(os2Locale,"OS2")==0) {
|
||||
locale->Assign(NS_LITERAL_STRING("en-US"));
|
||||
locale.Assign(NS_LITERAL_STRING("en-US"));
|
||||
return NS_OK;
|
||||
}
|
||||
if (!ParseLocaleString(os2Locale,lang_code,country_code,extra,'_')) {
|
||||
// * locale = "x-user-defined";
|
||||
locale->AssignWithConversion(os2Locale); // use os2 if parse failed
|
||||
CopyASCIItoUTF16(os2Locale, locale); // use os2 if parse failed
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ nsOS2Locale::GetXPLocale(const char* os2Locale, nsString* locale)
|
||||
}
|
||||
}
|
||||
|
||||
locale->AssignWithConversion(os2_locale);
|
||||
CopyASCIItoUTF16(os2_locale, locale);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(PRUnichar* os2Locale,
|
||||
size_t length);
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsString* locale);
|
||||
NS_IMETHOD GetXPLocale(const char* os2Locale, nsAutoString& locale);
|
||||
|
||||
protected:
|
||||
inline PRBool ParseLocaleString(const char* locale_string, char* language, char* country, char* extra, char separator);
|
||||
|
||||
@@ -115,51 +115,43 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale)
|
||||
// default platform locale
|
||||
mLocale.Assign('C');
|
||||
|
||||
PRUnichar *aLocaleUnichar = NULL;
|
||||
nsString aCategory;
|
||||
aCategory.Assign(NS_LITERAL_STRING("NSILOCALE_COLLATE##PLATFORM"));
|
||||
nsAutoString localeStr;
|
||||
NS_NAMED_LITERAL_STRING(aCategory, "NSILOCALE_COLLATE##PLATFORM");
|
||||
|
||||
// get locale string, use app default if no locale specified
|
||||
if (locale == nsnull) {
|
||||
nsCOMPtr<nsILocaleService> localeService =
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsILocale *appLocale;
|
||||
res = localeService->GetApplicationLocale(&appLocale);
|
||||
nsCOMPtr<nsILocale> appLocale;
|
||||
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = appLocale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
res = appLocale->GetCategory(aCategory, localeStr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get app locale info");
|
||||
appLocale->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
res = locale->GetCategory(aCategory, localeStr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get locale info");
|
||||
}
|
||||
|
||||
// Get platform locale and charset name from locale, if available
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsString aLocale;
|
||||
aLocale = aLocaleUnichar;
|
||||
if (NULL != aLocaleUnichar) {
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
}
|
||||
|
||||
// keep the same behavior as 4.x as well as avoiding Linux collation key problem
|
||||
if (aLocale.EqualsIgnoreCase("en_US")) { // note: locale is in platform format
|
||||
aLocale.Assign(NS_LITERAL_STRING("C"));
|
||||
if (localeStr.EqualsIgnoreCase("en_US")) { // note: locale is in platform format
|
||||
localeStr.Assign(NS_LITERAL_STRING("C"));
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(NS_POSIXLOCALE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = posixLocale->GetPlatformLocale(&aLocale, mLocale);
|
||||
res = posixLocale->GetPlatformLocale(localeStr, mLocale);
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsCAutoString mappedCharset;
|
||||
res = platformCharset->GetDefaultCharsetForLocale(aLocale.get(), mappedCharset);
|
||||
res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mCollation->SetCharset(mappedCharset.get());
|
||||
}
|
||||
|
||||
@@ -55,28 +55,25 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatUnix, nsIDateTimeFormat)
|
||||
// init this interface to a specified locale
|
||||
nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
|
||||
{
|
||||
PRUnichar *aLocaleUnichar = NULL;
|
||||
nsString aCategory;
|
||||
aCategory.Assign(NS_LITERAL_STRING("NSILOCALE_TIME##PLATFORM"));
|
||||
nsAutoString localeStr;
|
||||
NS_NAMED_LITERAL_STRING(aCategory, "NSILOCALE_TIME##PLATFORM");
|
||||
nsresult res = NS_OK;
|
||||
|
||||
// use cached info if match with stored locale
|
||||
if (NULL == locale) {
|
||||
if (mLocale.Length() &&
|
||||
if (!mLocale.IsEmpty() &&
|
||||
mLocale.Equals(mAppLocale, nsCaseInsensitiveStringComparator())) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
res = locale->GetCategory(aCategory, localeStr);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
if (!mLocale.IsEmpty() &&
|
||||
mLocale.Equals(aLocaleUnichar,
|
||||
mLocale.Equals(localeStr,
|
||||
nsCaseInsensitiveStringComparator())) {
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
return NS_OK;
|
||||
}
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,36 +85,34 @@ nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
|
||||
nsCOMPtr<nsILocaleService> localeService =
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsILocale *appLocale;
|
||||
res = localeService->GetApplicationLocale(&appLocale);
|
||||
nsCOMPtr<nsILocale> appLocale;
|
||||
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = appLocale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
res = appLocale->GetCategory(aCategory, localeStr);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get app locale info");
|
||||
mAppLocale = aLocaleUnichar; // cache app locale name
|
||||
mAppLocale = localeStr; // cache app locale name
|
||||
}
|
||||
appLocale->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
res = locale->GetCategory(aCategory, localeStr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get locale info");
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
mLocale = aLocaleUnichar; // cache locale name
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
mLocale = localeStr; // cache locale name
|
||||
|
||||
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(NS_POSIXLOCALE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = posixLocale->GetPlatformLocale(&mLocale, mPlatformLocale);
|
||||
res = posixLocale->GetPlatformLocale(mLocale, mPlatformLocale);
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsCAutoString mappedCharset;
|
||||
res = platformCharset->GetDefaultCharsetForLocale(mLocale.get(), mappedCharset);
|
||||
res = platformCharset->GetDefaultCharsetForLocale(mLocale, mappedCharset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mCharset = mappedCharset;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "nsLocaleCID.h"
|
||||
#include "prprf.h"
|
||||
#include "plstr.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
/* nsPosixLocale ISupports */
|
||||
NS_IMPL_ISUPPORTS1(nsPosixLocale, nsIPosixLocale)
|
||||
@@ -58,15 +59,15 @@ nsPosixLocale::~nsPosixLocale(void)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPosixLocale::GetPlatformLocale(const nsString* locale, nsACString& posixLocale)
|
||||
nsPosixLocale::GetPlatformLocale(const nsAString& locale, nsACString& posixLocale)
|
||||
{
|
||||
char country_code[MAX_COUNTRY_CODE_LEN+1];
|
||||
char lang_code[MAX_LANGUAGE_CODE_LEN+1];
|
||||
char extra[MAX_EXTRA_LEN+1];
|
||||
char posix_locale[MAX_LOCALE_LEN+1];
|
||||
NS_LossyConvertUCS2toASCII xp_locale(*locale);
|
||||
NS_LossyConvertUTF16toASCII xp_locale(locale);
|
||||
|
||||
if (xp_locale.get()) {
|
||||
if (!xp_locale.IsEmpty()) {
|
||||
if (!ParseLocaleString(xp_locale.get(),lang_code,country_code,extra,'-')) {
|
||||
// strncpy(posixLocale,"C",length);
|
||||
posixLocale = xp_locale; // use xp locale if parse failed
|
||||
@@ -98,7 +99,7 @@ nsPosixLocale::GetPlatformLocale(const nsString* locale, nsACString& posixLocale
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPosixLocale::GetXPLocale(const char* posixLocale, nsString* locale)
|
||||
nsPosixLocale::GetXPLocale(const char* posixLocale, nsAString& locale)
|
||||
{
|
||||
char country_code[MAX_COUNTRY_CODE_LEN+1];
|
||||
char lang_code[MAX_LANGUAGE_CODE_LEN+1];
|
||||
@@ -107,12 +108,13 @@ nsPosixLocale::GetXPLocale(const char* posixLocale, nsString* locale)
|
||||
|
||||
if (posixLocale!=nsnull) {
|
||||
if (strcmp(posixLocale,"C")==0 || strcmp(posixLocale,"POSIX")==0) {
|
||||
locale->Assign(NS_LITERAL_STRING("en-US"));
|
||||
locale.Assign(NS_LITERAL_STRING("en-US"));
|
||||
return NS_OK;
|
||||
}
|
||||
if (!ParseLocaleString(posixLocale,lang_code,country_code,extra,'_')) {
|
||||
// * locale = "x-user-defined";
|
||||
locale->AssignWithConversion(posixLocale); // use posix if parse failed
|
||||
// use posix if parse failed
|
||||
CopyASCIItoUTF16(nsDependentCString(posixLocale), locale);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -123,7 +125,7 @@ nsPosixLocale::GetXPLocale(const char* posixLocale, nsString* locale)
|
||||
PR_snprintf(posix_locale,sizeof(posix_locale),"%s",lang_code);
|
||||
}
|
||||
|
||||
locale->AssignWithConversion(posix_locale);
|
||||
CopyASCIItoUTF16(nsDependentCString(posix_locale), locale);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
nsPosixLocale();
|
||||
virtual ~nsPosixLocale();
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale, nsACString& posixLocale);
|
||||
NS_IMETHOD GetXPLocale(const char* posixLocale, nsString* locale);
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale, nsACString& posixLocale);
|
||||
NS_IMETHOD GetXPLocale(const char* posixLocale, nsAString& locale);
|
||||
|
||||
protected:
|
||||
inline PRBool ParseLocaleString(const char* locale_string, char* language, char* country, char* extra, char separator);
|
||||
|
||||
@@ -72,15 +72,14 @@ nsresult nsCollationWin::Initialize(nsILocale* locale)
|
||||
nsresult res;
|
||||
|
||||
mCollation = new nsCollation;
|
||||
if (mCollation == NULL) {
|
||||
if (!mCollation) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
OSVERSIONINFO os;
|
||||
os.dwOSVersionInfoSize = sizeof(os);
|
||||
::GetVersionEx(&os);
|
||||
if (VER_PLATFORM_WIN32_NT == os.dwPlatformId &&
|
||||
os.dwMajorVersion >= 4) {
|
||||
if (VER_PLATFORM_WIN32_NT == os.dwPlatformId && os.dwMajorVersion >= 4) {
|
||||
mW_API = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
@@ -90,50 +89,44 @@ nsresult nsCollationWin::Initialize(nsILocale* locale)
|
||||
// default LCID (en-US)
|
||||
mLCID = 1033;
|
||||
|
||||
PRUnichar *aLocaleUnichar = NULL;
|
||||
nsString aCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"));
|
||||
nsAutoString localeStr;
|
||||
|
||||
// get locale string, use app default if no locale specified
|
||||
if (locale == nsnull) {
|
||||
if (!locale) {
|
||||
nsCOMPtr<nsILocaleService> localeService =
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsILocale *appLocale;
|
||||
res = localeService->GetApplicationLocale(&appLocale);
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID);
|
||||
if (localeService) {
|
||||
nsCOMPtr<nsILocale> appLocale;
|
||||
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = appLocale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
appLocale->Release();
|
||||
res = appLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"),
|
||||
localeStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"),
|
||||
localeStr);
|
||||
}
|
||||
|
||||
// Get LCID and charset name from locale, if available
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsString aLocale;
|
||||
aLocale.Assign(aLocaleUnichar);
|
||||
if (NULL != aLocaleUnichar) {
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(NS_WIN32LOCALE_CONTRACTID, &res);
|
||||
nsCOMPtr <nsIWin32Locale> win32Locale =
|
||||
do_GetService(NS_WIN32LOCALE_CONTRACTID);
|
||||
if (win32Locale) {
|
||||
LCID lcid;
|
||||
res = win32Locale->GetPlatformLocale(localeStr, &lcid);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
LCID lcid;
|
||||
res = win32Locale->GetPlatformLocale(&aLocale, &lcid);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mLCID = lcid;
|
||||
}
|
||||
mLCID = lcid;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset =
|
||||
do_GetService(NS_PLATFORMCHARSET_CONTRACTID);
|
||||
if (platformCharset) {
|
||||
nsCAutoString mappedCharset;
|
||||
res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsCAutoString mappedCharset;
|
||||
res = platformCharset->GetDefaultCharsetForLocale(aLocale.get(), mappedCharset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
mCollation->SetCharset(mappedCharset.get());
|
||||
}
|
||||
mCollation->SetCharset(mappedCharset.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,24 +57,23 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatWin, nsIDateTimeFormat)
|
||||
// init this interface to a specified locale
|
||||
nsresult nsDateTimeFormatWin::Initialize(nsILocale* locale)
|
||||
{
|
||||
PRUnichar *aLocaleUnichar = NULL;
|
||||
nsString aCategory(NS_LITERAL_STRING("NSILOCALE_TIME"));
|
||||
nsAutoString localeStr;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
// use cached info if match with stored locale
|
||||
if (NULL == locale) {
|
||||
if (mLocale.Length() && mLocale.Equals(mAppLocale, nsCaseInsensitiveStringComparator())) {
|
||||
if (!mLocale.IsEmpty() &&
|
||||
mLocale.Equals(mAppLocale, nsCaseInsensitiveStringComparator())) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
if (mLocale.Length() && mLocale.Equals(nsDependentString(aLocaleUnichar), nsCaseInsensitiveStringComparator())) {
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
if (!mLocale.IsEmpty() &&
|
||||
mLocale.Equals(localeStr, nsCaseInsensitiveStringComparator())) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +81,7 @@ nsresult nsDateTimeFormatWin::Initialize(nsILocale* locale)
|
||||
OSVERSIONINFO os;
|
||||
os.dwOSVersionInfoSize = sizeof(os);
|
||||
::GetVersionEx(&os);
|
||||
if (VER_PLATFORM_WIN32_NT == os.dwPlatformId &&
|
||||
os.dwMajorVersion >= 4) {
|
||||
if (VER_PLATFORM_WIN32_NT == os.dwPlatformId && os.dwMajorVersion >= 4) {
|
||||
mW_API = PR_TRUE; // has W API
|
||||
}
|
||||
else {
|
||||
@@ -96,31 +94,30 @@ nsresult nsDateTimeFormatWin::Initialize(nsILocale* locale)
|
||||
// get locale string, use app default if no locale specified
|
||||
if (NULL == locale) {
|
||||
nsCOMPtr<nsILocaleService> localeService =
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsILocale *appLocale;
|
||||
res = localeService->GetApplicationLocale(&appLocale);
|
||||
do_GetService(NS_LOCALESERVICE_CONTRACTID);
|
||||
if (localeService) {
|
||||
nsCOMPtr<nsILocale> appLocale;
|
||||
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = appLocale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
mAppLocale.Assign(aLocaleUnichar); // cache app locale name
|
||||
res = appLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"),
|
||||
localeStr);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
mAppLocale.Assign(localeStr); // cache app locale name
|
||||
}
|
||||
appLocale->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
res = locale->GetCategory(aCategory.get(), &aLocaleUnichar);
|
||||
res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr);
|
||||
}
|
||||
|
||||
// Get LCID and charset name from locale, if available
|
||||
if (NS_SUCCEEDED(res) && NULL != aLocaleUnichar) {
|
||||
mLocale.Assign(aLocaleUnichar); // cache locale name
|
||||
nsMemory::Free(aLocaleUnichar);
|
||||
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
|
||||
mLocale.Assign(localeStr); // cache locale name
|
||||
|
||||
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(NS_WIN32LOCALE_CONTRACTID, &res);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = win32Locale->GetPlatformLocale(&mLocale, (LCID *) &mLCID);
|
||||
nsCOMPtr <nsIWin32Locale> win32Locale = do_GetService(NS_WIN32LOCALE_CONTRACTID);
|
||||
if (win32Locale) {
|
||||
res = win32Locale->GetPlatformLocale(mLocale, (LCID *) &mLCID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +141,7 @@ nsresult nsDateTimeFormatWin::FormatTMTime(nsILocale* locale,
|
||||
const struct tm* tmTime,
|
||||
nsString& stringOut)
|
||||
{
|
||||
SYSTEMTIME system_time;
|
||||
SYSTEMTIME system_time;
|
||||
DWORD dwFlags_Date = 0, dwFlags_Time = 0;
|
||||
int dateLen, timeLen;
|
||||
PRUnichar dateBuffer[NSDATETIMEFORMAT_BUFFER_LEN], timeBuffer[NSDATETIMEFORMAT_BUFFER_LEN];
|
||||
@@ -153,14 +150,14 @@ nsresult nsDateTimeFormatWin::FormatTMTime(nsILocale* locale,
|
||||
(void) Initialize(locale);
|
||||
|
||||
// Map tm to SYSTEMTIME
|
||||
system_time.wYear = 1900 + tmTime->tm_year;
|
||||
system_time.wMonth = tmTime->tm_mon + 1;
|
||||
system_time.wDayOfWeek = tmTime->tm_wday;
|
||||
system_time.wDay = tmTime->tm_mday;
|
||||
system_time.wHour = tmTime->tm_hour;
|
||||
system_time.wMinute = tmTime->tm_min;
|
||||
system_time.wSecond = tmTime->tm_sec;
|
||||
system_time.wMilliseconds = 0;
|
||||
system_time.wYear = 1900 + tmTime->tm_year;
|
||||
system_time.wMonth = tmTime->tm_mon + 1;
|
||||
system_time.wDayOfWeek = tmTime->tm_wday;
|
||||
system_time.wDay = tmTime->tm_mday;
|
||||
system_time.wHour = tmTime->tm_hour;
|
||||
system_time.wMinute = tmTime->tm_min;
|
||||
system_time.wSecond = tmTime->tm_sec;
|
||||
system_time.wMilliseconds = 0;
|
||||
|
||||
// Map to WinAPI date format
|
||||
switch (dateFormatSelector) {
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "prprf.h"
|
||||
#include <windows.h>
|
||||
#include "nsCRT.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
#define USER_DEFINED_PRIMARYLANG 0x0200
|
||||
#define USER_DEFINED_SUBLANGUAGE 0x20
|
||||
@@ -422,14 +423,14 @@ nsIWin32LocaleImpl::~nsIWin32LocaleImpl(void)
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIWin32LocaleImpl::GetPlatformLocale(const nsString* locale,LCID* winLCID)
|
||||
nsIWin32LocaleImpl::GetPlatformLocale(const nsAString& locale,LCID* winLCID)
|
||||
{
|
||||
char language_code[3];
|
||||
char country_code[3];
|
||||
char region_code[3];
|
||||
int i,j;
|
||||
char language_code[3];
|
||||
char country_code[3];
|
||||
char region_code[3];
|
||||
int i,j;
|
||||
|
||||
if (!ParseLocaleString(*locale,language_code,country_code,region_code)) {
|
||||
if (!ParseLocaleString(NS_LossyConvertUTF16toASCII(locale).get(),language_code,country_code,region_code)) {
|
||||
*winLCID = MAKELCID(MAKELANGID(USER_DEFINED_PRIMARYLANG,USER_DEFINED_SUBLANGUAGE),
|
||||
SORT_DEFAULT);
|
||||
return NS_OK;
|
||||
@@ -438,7 +439,7 @@ nsIWin32LocaleImpl::GetPlatformLocale(const nsString* locale,LCID* winLCID)
|
||||
|
||||
for(i=0;i<LENGTH_MAPPING_LIST;i++) {
|
||||
if (strcmp(language_code,iso_list[i].iso_code)==0) {
|
||||
for(j=0;strlen(iso_list[i].sublang_list[j].iso_code)!=0;j++) {
|
||||
for(j=0;iso_list[i].sublang_list[j].win_code;j++) {
|
||||
if (strcmp(country_code,iso_list[i].sublang_list[j].iso_code)==0) {
|
||||
*winLCID = MAKELCID(MAKELANGID(iso_list[i].win_code,iso_list[i].sublang_list[j].win_code),SORT_DEFAULT);
|
||||
return NS_OK;
|
||||
@@ -449,52 +450,51 @@ nsIWin32LocaleImpl::GetPlatformLocale(const nsString* locale,LCID* winLCID)
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsString* locale)
|
||||
nsIWin32LocaleImpl::GetXPLocale(LCID winLCID, nsAString& locale)
|
||||
{
|
||||
DWORD lang_id, sublang_id;
|
||||
char rfc_locale_string[9];
|
||||
int i,j;
|
||||
DWORD lang_id, sublang_id;
|
||||
char rfc_locale_string[9];
|
||||
int i,j;
|
||||
|
||||
lang_id = PRIMARYLANGID(LANGIDFROMLCID(winLCID));
|
||||
sublang_id = SUBLANGID(LANGIDFROMLCID(winLCID));
|
||||
lang_id = PRIMARYLANGID(LANGIDFROMLCID(winLCID));
|
||||
sublang_id = SUBLANGID(LANGIDFROMLCID(winLCID));
|
||||
|
||||
for(i=0;i<LENGTH_MAPPING_LIST;i++) {
|
||||
if (lang_id==iso_list[i].win_code) {
|
||||
for(j=0;strlen(iso_list[i].sublang_list[j].iso_code)!=0;j++) {
|
||||
if (sublang_id == iso_list[i].sublang_list[j].win_code) {
|
||||
PR_snprintf(rfc_locale_string,9,"%s-%s%c",iso_list[i].iso_code,
|
||||
iso_list[i].sublang_list[j].iso_code,0);
|
||||
locale->AssignWithConversion(rfc_locale_string);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
// no sublang, so just lang
|
||||
PR_snprintf(rfc_locale_string,9,"%s%c",iso_list[i].iso_code,0);
|
||||
locale->AssignWithConversion(rfc_locale_string);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
for(i=0;i<LENGTH_MAPPING_LIST;i++) {
|
||||
if (lang_id==iso_list[i].win_code) {
|
||||
for(j=0;iso_list[i].sublang_list[j].win_code;j++) {
|
||||
if (sublang_id == iso_list[i].sublang_list[j].win_code) {
|
||||
PR_snprintf(rfc_locale_string,9,"%s-%s%c",iso_list[i].iso_code,
|
||||
iso_list[i].sublang_list[j].iso_code,0);
|
||||
CopyASCIItoUTF16(nsDependentCString(rfc_locale_string), locale);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
// no sublang, so just lang
|
||||
PR_snprintf(rfc_locale_string,9,"%s%c",iso_list[i].iso_code,0);
|
||||
CopyASCIItoUTF16(nsDependentCString(rfc_locale_string), locale);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// totally didn't find it
|
||||
//
|
||||
return NS_ERROR_FAILURE;
|
||||
//
|
||||
// totally didn't find it
|
||||
//
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// returns PR_FALSE/PR_TRUE depending on if it was of the form LL-CC-RR
|
||||
PRBool
|
||||
nsIWin32LocaleImpl::ParseLocaleString(const nsString& locale_string, char* language, char* country, char* region)
|
||||
nsIWin32LocaleImpl::ParseLocaleString(const char* locale_string, char* language, char* country, char* region)
|
||||
{
|
||||
size_t len;
|
||||
size_t len = strlen(locale_string);
|
||||
|
||||
len = locale_string.Length();
|
||||
if (len==0 || (len!=2 && len!=5 && len!=8))
|
||||
return PR_FALSE;
|
||||
|
||||
|
||||
@@ -57,11 +57,11 @@ public:
|
||||
nsIWin32LocaleImpl(void);
|
||||
~nsIWin32LocaleImpl(void);
|
||||
|
||||
NS_IMETHOD GetPlatformLocale(const nsString* locale,LCID* winLCID);
|
||||
NS_IMETHOD GetXPLocale(LCID winLCID,nsString* locale);
|
||||
NS_IMETHOD GetPlatformLocale(const nsAString& locale, LCID* winLCID);
|
||||
NS_IMETHOD GetXPLocale(LCID winLCID, nsAString& locale);
|
||||
|
||||
protected:
|
||||
inline PRBool ParseLocaleString(const nsString& locale_string, char* language, char* country, char* region);
|
||||
inline PRBool ParseLocaleString(const char* locale_string, char* language, char* country, char* region);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -842,124 +842,114 @@ static void TestDateTimeFormat(nsILocale *locale)
|
||||
|
||||
static nsresult NewLocale(const nsString* localeName, nsILocale** locale)
|
||||
{
|
||||
nsILocaleFactory* localeFactory;
|
||||
nsCOMPtr<nsILocaleFactory> localeFactory;
|
||||
nsresult res;
|
||||
|
||||
res = nsComponentManager::FindFactory(kLocaleFactoryCID, (nsIFactory**)&localeFactory);
|
||||
res = nsComponentManager::FindFactory(kLocaleFactoryCID, getter_AddRefs(localeFactory));
|
||||
if (NS_FAILED(res) || localeFactory == nsnull) cout << "FindFactory nsILocaleFactory failed\n";
|
||||
|
||||
res = localeFactory->NewLocale(localeName, locale);
|
||||
if (NS_FAILED(res) || locale == nsnull) cout << "NewLocale failed\n";
|
||||
|
||||
localeFactory->Release();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void Test_nsLocale()
|
||||
{
|
||||
#if defined(XP_MAC) || defined(XP_MACOSX)
|
||||
nsString localeName;
|
||||
nsIMacLocale* macLocale;
|
||||
nsAutoString localeName;
|
||||
nsCOMPtr<nsIMacLocale> macLocale;
|
||||
short script, lang;
|
||||
nsresult res;
|
||||
|
||||
if (NS_SUCCEEDED(res = nsComponentManager::CreateInstance(
|
||||
kMacLocaleFactoryCID, NULL, kIMacLocaleIID, (void**)&macLocale))) {
|
||||
|
||||
localeName.SetString("en-US");
|
||||
res = macLocale->GetPlatformLocale(&localeName, &script, &lang);
|
||||
nsCOMPtr<nsIMacLocale> win32Locale = do_CreateInstance(kMacLocaleFactoryCID);
|
||||
if (macLocale) {
|
||||
localeName = NS_LITERAL_STRING("en-US");
|
||||
res = macLocale->GetPlatformLocale(localeName, &script, &lang);
|
||||
printf("script for en-US is 0\n");
|
||||
printf("result: script = %d lang = %d\n", script, lang);
|
||||
|
||||
localeName.SetString("en-GB");
|
||||
res = macLocale->GetPlatformLocale(&localeName, &script, &lang);
|
||||
localeName = NS_LITERAL_STRING("en-GB");
|
||||
res = macLocale->GetPlatformLocale(localeName, &script, &lang);
|
||||
printf("script for en-GB is 0\n");
|
||||
printf("result: script = %d lang = %d\n", script, lang);
|
||||
|
||||
localeName.SetString("fr-FR");
|
||||
res = macLocale->GetPlatformLocale(&localeName, &script, &lang);
|
||||
localeName = NS_LITERAL_STRING("fr-FR");
|
||||
res = macLocale->GetPlatformLocale(localeName, &script, &lang);
|
||||
printf("script for fr-FR is 0\n");
|
||||
printf("result: script = %d lang = %d\n", script, lang);
|
||||
|
||||
localeName.SetString("de-DE");
|
||||
res = macLocale->GetPlatformLocale(&localeName, &script, &lang);
|
||||
localeName = NS_LITERAL_STRING("de-DE");
|
||||
res = macLocale->GetPlatformLocale(localeName, &script, &lang);
|
||||
printf("script for de-DE is 0\n");
|
||||
printf("result: script = %d lang = %d\n", script, lang);
|
||||
|
||||
localeName.SetString("ja-JP");
|
||||
res = macLocale->GetPlatformLocale(&localeName, &script, &lang);
|
||||
localeName = NS_LITERAL_STRING("ja-JP");
|
||||
res = macLocale->GetPlatformLocale(localeName, &script, &lang);
|
||||
printf("script for ja-JP is 1\n");
|
||||
printf("result: script = %d lang = %d\n", script, lang);
|
||||
|
||||
macLocale->Release();
|
||||
}
|
||||
#elif defined(XP_WIN) || defined(XP_OS2)
|
||||
nsString localeName;
|
||||
nsIWin32Locale* win32Locale;
|
||||
nsAutoString localeName;
|
||||
LCID lcid;
|
||||
nsresult res;
|
||||
|
||||
if (NS_SUCCEEDED(res = nsComponentManager::CreateInstance(
|
||||
kWin32LocaleFactoryCID, NULL, kIWin32LocaleIID, (void**)&win32Locale))) {
|
||||
|
||||
localeName.SetString("en-US");
|
||||
res = win32Locale->GetPlatformLocale(&localeName, &lcid);
|
||||
nsCOMPtr<nsIWin32Locale> win32Locale = do_CreateInstance(kWin32LocaleFactoryCID);
|
||||
if (win32Locale) {
|
||||
localeName = NS_LITERAL_STRING("en-US");
|
||||
res = win32Locale->GetPlatformLocale(localeName, &lcid);
|
||||
printf("LCID for en-US is 1033\n");
|
||||
printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid);
|
||||
|
||||
localeName.SetString("en-GB");
|
||||
res = win32Locale->GetPlatformLocale(&localeName, &lcid);
|
||||
localeName = NS_LITERAL_STRING("en-GB");
|
||||
res = win32Locale->GetPlatformLocale(localeName, &lcid);
|
||||
printf("LCID for en-GB is 2057\n");
|
||||
printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid);
|
||||
|
||||
localeName.SetString("fr-FR");
|
||||
res = win32Locale->GetPlatformLocale(&localeName, &lcid);
|
||||
localeName = NS_LITERAL_STRING("fr-FR");
|
||||
res = win32Locale->GetPlatformLocale(localeName, &lcid);
|
||||
printf("LCID for fr-FR is 1036\n");
|
||||
printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid);
|
||||
|
||||
localeName.SetString("de-DE");
|
||||
res = win32Locale->GetPlatformLocale(&localeName, &lcid);
|
||||
localeName = NS_LITERAL_STRING("de-DE");
|
||||
res = win32Locale->GetPlatformLocale(localeName, &lcid);
|
||||
printf("LCID for de-DE is 1031\n");
|
||||
printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid);
|
||||
|
||||
localeName.SetString("ja-JP");
|
||||
res = win32Locale->GetPlatformLocale(&localeName, &lcid);
|
||||
localeName = NS_LITERAL_STRING("ja-JP");
|
||||
res = win32Locale->GetPlatformLocale(localeName, &lcid);
|
||||
printf("LCID for ja-JP is 1041\n");
|
||||
printf("result: locale = %s LCID = 0x%0.4x %d\n", NS_LossyConvertUCS2toASCII(localeName).get(), lcid, lcid);
|
||||
|
||||
win32Locale->Release();
|
||||
}
|
||||
#else
|
||||
nsString localeName;
|
||||
nsAutoString localeName;
|
||||
char locale[32];
|
||||
size_t length = 32;
|
||||
nsIPosixLocale* posixLocale;
|
||||
nsresult res;
|
||||
|
||||
if (NS_SUCCEEDED(res = nsComponentManager::CreateInstance(
|
||||
kPosixLocaleFactoryCID, NULL, kIPosixLocaleIID, (void**)&posixLocale))) {
|
||||
localeName.SetString("en-US");
|
||||
res = posixLocale->GetPlatformLocale(&localeName, locale, length);
|
||||
nsCOMPtr<nsIPosixLocale> posixLocale = do_CreateInstance(kPosixLocaleFactoryCID);
|
||||
if (posixLocale) {
|
||||
localeName = NS_LITERAL_STRING("en-US");
|
||||
res = posixLocale->GetPlatformLocale(localeName, locale, length);
|
||||
printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale);
|
||||
|
||||
localeName.SetString("en-GB");
|
||||
res = posixLocale->GetPlatformLocale(&localeName, locale, length);
|
||||
localeName = NS_LITERAL_STRING("en-GB");
|
||||
res = posixLocale->GetPlatformLocale(localeName, locale, length);
|
||||
printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale);
|
||||
|
||||
localeName.SetString("fr-FR");
|
||||
res = posixLocale->GetPlatformLocale(&localeName, locale, length);
|
||||
localeName = NS_LITERAL_STRING("fr-FR");
|
||||
res = posixLocale->GetPlatformLocale(localeName, locale, length);
|
||||
printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale);
|
||||
|
||||
localeName.SetString("de-DE");
|
||||
res = posixLocale->GetPlatformLocale(&localeName, locale, length);
|
||||
localeName = NS_LITERAL_STRING("de-DE");
|
||||
res = posixLocale->GetPlatformLocale(localeName, locale, length);
|
||||
printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale);
|
||||
|
||||
localeName.SetString("ja-JP");
|
||||
res = posixLocale->GetPlatformLocale(&localeName, locale, length);
|
||||
localeName = NS_LITERAL_STRING("ja-JP");
|
||||
res = posixLocale->GetPlatformLocale(localeName, locale, length);
|
||||
printf("result: locale = %s POSIX = %s\n", NS_LossyConvertUCS2toASCII(localeName).get(), locale);
|
||||
|
||||
posixLocale->Release();
|
||||
}
|
||||
else {
|
||||
printf("Fail: CreateInstance PosixLocale\n");
|
||||
@@ -1027,17 +1017,16 @@ int main(int argc, char** argv) {
|
||||
argc = make_args(mac_argv);
|
||||
argv = mac_argv;
|
||||
#endif//XP_MAC
|
||||
nsILocale *locale = NULL;
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
nsresult res;
|
||||
|
||||
nsILocaleFactory* localeFactory = nsnull;
|
||||
nsCOMPtr<nsILocaleFactory> localeFactory;
|
||||
|
||||
res = nsComponentManager::FindFactory(kLocaleFactoryCID, (nsIFactory**)&localeFactory);
|
||||
res = nsComponentManager::FindFactory(kLocaleFactoryCID, getter_AddRefs(localeFactory));
|
||||
if (NS_FAILED(res) || localeFactory == nsnull) cout << "FindFactory nsILocaleFactory failed\n";
|
||||
|
||||
res = localeFactory->GetApplicationLocale(&locale);
|
||||
res = localeFactory->GetApplicationLocale(getter_AddRefs(locale));
|
||||
if (NS_FAILED(res) || locale == nsnull) cout << "GetApplicationLocale failed\n";
|
||||
localeFactory->Release();
|
||||
|
||||
// --------------------------------------------
|
||||
nsCollationStrength strength = kCollationCaseInSensitive;
|
||||
@@ -1076,22 +1065,17 @@ int main(int argc, char** argv) {
|
||||
s = get_option(argc, argv, "-locale");
|
||||
if (s) {
|
||||
nsString localeName(s);
|
||||
NS_IF_RELEASE(locale);
|
||||
res = NewLocale(&localeName, &locale); // reset the locale
|
||||
res = NewLocale(localeName, getter_AddRefs(locale)); // reset the locale
|
||||
}
|
||||
|
||||
// print locale string
|
||||
PRUnichar *localeUnichar;
|
||||
nsString aLocaleString, aCategory("NSILOCALE_COLLATE");
|
||||
locale->GetCategory(aCategory.get(), &localeUnichar);
|
||||
aLocaleString.SetString(localeUnichar);
|
||||
nsAutoString localeStr;
|
||||
locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), localeStr);
|
||||
cout << "locale setting for collation is ";
|
||||
DebugDump(aLocaleString, cout);
|
||||
aCategory.SetString("NSILOCALE_TIME");
|
||||
locale->GetCategory(aCategory.get(), &localeUnichar);
|
||||
aLocaleString.SetString(localeUnichar);
|
||||
DebugDump(localeStr, cout);
|
||||
locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME"), localeStr);
|
||||
cout << "locale setting for time is ";
|
||||
DebugDump(aLocaleString, cout);
|
||||
DebugDump(localeStr, cout);
|
||||
|
||||
while (argc--) {
|
||||
if (!strcmp(argv[argc], "-col"))
|
||||
@@ -1108,7 +1092,6 @@ int main(int argc, char** argv) {
|
||||
fclose(g_outfp);
|
||||
}
|
||||
}
|
||||
NS_IF_RELEASE(locale);
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
|
||||
@@ -131,79 +131,57 @@ void
|
||||
factory_test_isupports(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsILocaleFactory* localeFactory;
|
||||
nsISupports* genericInterface1, *genericInterface2;
|
||||
nsIFactory* genericFactory1, *genericFactory2;
|
||||
nsCOMPtr<nsILocaleFactory> localeFactory;
|
||||
nsCOMPtr<nsISupports> genericInterface1, genericInterface2;
|
||||
nsCOMPtr<nsIFactory> genericFactory1, genericFactory2;
|
||||
|
||||
result = nsComponentManager::FindFactory(kLocaleFactoryCID,
|
||||
(nsIFactory**)&localeFactory);
|
||||
NS_ASSERTION(localeFactory!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
getter_AddRefs(localeFactory));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
//
|
||||
// test AddRef
|
||||
localeFactory->AddRef();
|
||||
|
||||
//
|
||||
// test Release
|
||||
//
|
||||
localeFactory->Release();
|
||||
|
||||
//
|
||||
// test generic interface
|
||||
//
|
||||
result = localeFactory->QueryInterface(kISupportsIID,(void**)&genericInterface1);
|
||||
result = localeFactory->QueryInterface(kISupportsIID, getter_AddRefs(genericInterface1));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed.");
|
||||
NS_ASSERTION(genericInterface1!=NULL,"nsLocaleTest: factory_test_isupports failed.");
|
||||
|
||||
result = localeFactory->QueryInterface(kISupportsIID,(void**)&genericInterface2);
|
||||
result = localeFactory->QueryInterface(kISupportsIID, getter_AddRefs(genericInterface2));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed.");
|
||||
NS_ASSERTION(genericInterface2!=NULL,"nsLocaleTest: factory_test_isupports failed.");
|
||||
NS_ASSERTION(genericInterface1==genericInterface2,"nsLocaleTest: factory_test_isupports failed.");
|
||||
|
||||
genericInterface1->Release();
|
||||
genericInterface2->Release();
|
||||
|
||||
//
|
||||
// test generic factory
|
||||
//
|
||||
result = localeFactory->QueryInterface(kIFactoryIID,(void**)&genericFactory1);
|
||||
result = localeFactory->QueryInterface(kIFactoryIID, getter_AddRefs(genericFactory1));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed.");
|
||||
NS_ASSERTION(genericFactory1!=NULL,"nsLocaleTest: factory_test_isupports failed.");
|
||||
|
||||
result = localeFactory->QueryInterface(kIFactoryIID,(void**)&genericFactory2);
|
||||
result = localeFactory->QueryInterface(kIFactoryIID, getter_AddRefs(genericFactory2));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_test_isupports failed.");
|
||||
NS_ASSERTION(genericFactory1!=NULL,"nsLocaleTest: factory_test_isupports failed.");
|
||||
NS_ASSERTION(genericFactory1==genericFactory2,"nsLocaleTest: factory_test_isupports failed.");
|
||||
|
||||
genericFactory1->Release();
|
||||
genericFactory2->Release();
|
||||
|
||||
localeFactory->Release();
|
||||
}
|
||||
|
||||
void
|
||||
factory_new_locale(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsILocaleFactory* localeFactory;
|
||||
nsILocale* locale;
|
||||
nsString* localeName, *category, *value;
|
||||
nsCOMPtr<nsILocaleFactory> localeFactory;
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
nsString* *category, *value;
|
||||
int i;
|
||||
nsString** categoryList, **valueList;
|
||||
PRUnichar *lc_name_unichar;
|
||||
|
||||
result = nsComponentManager::FindFactory(kLocaleFactoryCID,
|
||||
(nsIFactory**)&localeFactory);
|
||||
NS_ASSERTION(localeFactory!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
getter_AddRefs(localeFactory));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
|
||||
//
|
||||
// test NewLocale
|
||||
//
|
||||
localeName = new nsString("ja-JP");
|
||||
result = localeFactory->NewLocale(localeName,&locale);
|
||||
nsAutoString localeName(NS_LITERALSTRING("ja-JP"));
|
||||
result = localeFactory->NewLocale(localeName, getter_AddRefs(locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_new_interface failed");
|
||||
NS_ASSERTION(locale!=NULL,"nsLocaleTest: factory_new_interface failed");
|
||||
|
||||
@@ -212,23 +190,21 @@ factory_new_locale(void)
|
||||
category = new nsString(localeCategoryList[i]);
|
||||
value = new nsString();
|
||||
|
||||
result = locale->GetCategory(category->get(),&lc_name_unichar);
|
||||
result = locale->GetCategory(category, &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_new_interface failed");
|
||||
|
||||
value->SetString(lc_name_unichar);
|
||||
delete category;
|
||||
delete value;
|
||||
}
|
||||
delete localeName;
|
||||
locale->Release();
|
||||
|
||||
categoryList = new nsString*[6];
|
||||
valueList = new nsString*[6];
|
||||
categoryList = new nsStringArray(6);
|
||||
valueList = new nsStringArray(6);
|
||||
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
categoryList[i] = new nsString(localeCategoryList[i]);
|
||||
valueList[i] = new nsString("x-netscape");
|
||||
categoryList.InsertStringAt(localeCategoryList[i], i);
|
||||
valueList[i] = InsertStringAt(NS_LITERAL_STRING("x-netscape"), i);
|
||||
}
|
||||
|
||||
result = localeFactory->NewLocale(categoryList,valueList,6,&locale);
|
||||
@@ -238,7 +214,7 @@ factory_new_locale(void)
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
value = new nsString();
|
||||
result = locale->GetCategory(categoryList[i]->get(),&lc_name_unichar);
|
||||
result = locale->GetCategory(categoryList[i], &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_new_interface failed");
|
||||
|
||||
value->SetString(lc_name_unichar);
|
||||
@@ -247,16 +223,12 @@ factory_new_locale(void)
|
||||
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
delete categoryList[i];
|
||||
delete valueList[i];
|
||||
delete categoryList.RemoveStringAt(i);
|
||||
delete valueList.RemoveStringAt(i);
|
||||
}
|
||||
|
||||
delete [] categoryList;
|
||||
delete [] valueList;
|
||||
|
||||
locale->Release();
|
||||
|
||||
localeFactory->Release();
|
||||
delete categoryList;
|
||||
delete valueList;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,24 +236,22 @@ void
|
||||
factory_get_locale(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsILocaleFactory* localeFactory;
|
||||
nsILocale* locale;
|
||||
nsCOMPtr<nsILocaleFactory> localeFactory;
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
nsString* category;
|
||||
nsString* value;
|
||||
const char* acceptLangString = "ja;q=0.9,en;q=1.0,*";
|
||||
PRUnichar *lc_name_unichar;
|
||||
|
||||
result = nsComponentManager::FindFactory(kLocaleFactoryCID,
|
||||
(nsIFactory**)&localeFactory);
|
||||
NS_ASSERTION(localeFactory!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
getter_AddRefs(localeFactory));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
//
|
||||
// get the application locale
|
||||
//
|
||||
result = localeFactory->GetApplicationLocale(&locale);
|
||||
result = localeFactory->GetApplicationLocale(getter_AddRefs(locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed");
|
||||
NS_ASSERTION(locale!=NULL,"nsLocaleTest: factory_get_locale failed");
|
||||
|
||||
//
|
||||
// test and make sure the locale is a valid Interface
|
||||
@@ -291,12 +261,10 @@ factory_get_locale(void)
|
||||
category = new nsString("NSILOCALE_CTYPE");
|
||||
value = new nsString();
|
||||
|
||||
result = locale->GetCategory(category->get(),&lc_name_unichar);
|
||||
result = locale->GetCategory(category, &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed");
|
||||
|
||||
value->SetString(lc_name_unichar);
|
||||
locale->Release();
|
||||
locale->Release();
|
||||
|
||||
delete category;
|
||||
delete value;
|
||||
@@ -304,14 +272,13 @@ factory_get_locale(void)
|
||||
//
|
||||
// test GetSystemLocale
|
||||
//
|
||||
result = localeFactory->GetSystemLocale(&locale);
|
||||
result = localeFactory->GetSystemLocale(getter_AddRefs(locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed");
|
||||
NS_ASSERTION(locale!=NULL,"nsLocaleTest: factory_get_locale failed");
|
||||
|
||||
//
|
||||
// test and make sure the locale is a valid Interface
|
||||
//
|
||||
locale->AddRef();
|
||||
|
||||
category = new nsString("NSILOCALE_CTYPE");
|
||||
value = new nsString();
|
||||
@@ -320,8 +287,6 @@ factory_get_locale(void)
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed");
|
||||
|
||||
value->SetString(lc_name_unichar);
|
||||
locale->Release();
|
||||
locale->Release();
|
||||
|
||||
delete category;
|
||||
delete value;
|
||||
@@ -329,30 +294,23 @@ factory_get_locale(void)
|
||||
//
|
||||
// test GetLocaleFromAcceptLanguage
|
||||
//
|
||||
result = localeFactory->GetLocaleFromAcceptLanguage(acceptLangString,&locale);
|
||||
result = localeFactory->GetLocaleFromAcceptLanguage(acceptLangString,getter_AddRefs(locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed");
|
||||
NS_ASSERTION(locale!=NULL,"nsLocaleTest: factory_get_locale failed");
|
||||
|
||||
//
|
||||
// test and make sure the locale is a valid Interface
|
||||
//
|
||||
locale->AddRef();
|
||||
|
||||
category = new nsString("NSILOCALE_CTYPE");
|
||||
value = new nsString();
|
||||
|
||||
result = locale->GetCategory(category->get(),&lc_name_unichar);
|
||||
result = locale->GetCategory(category, &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_get_locale failed");
|
||||
|
||||
value->SetString(lc_name_unichar);
|
||||
locale->Release();
|
||||
locale->Release();
|
||||
|
||||
delete category;
|
||||
delete value;
|
||||
|
||||
localeFactory->Release();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -389,13 +347,13 @@ win32locale_test(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsIWin32Locale* win32Locale;
|
||||
nsString* locale;
|
||||
nsAutoString locale;
|
||||
LCID loc_id;
|
||||
|
||||
//
|
||||
// test with a simple locale
|
||||
//
|
||||
locale = new nsString("en-US");
|
||||
locale = NS_LITERAL_STRING("en-US");
|
||||
loc_id = 0;
|
||||
|
||||
result = nsComponentManager::CreateInstance(kWin32LocaleFactoryCID,
|
||||
@@ -410,12 +368,11 @@ win32locale_test(void)
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// test with a not so simple locale
|
||||
//
|
||||
locale = new nsString("x-netscape");
|
||||
locale = NS_LITERAL_STRING("x-netscape");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
@@ -423,9 +380,8 @@ win32locale_test(void)
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(USER_DEFINED_PRIMARYLANG,USER_DEFINED_SUBLANGUAGE),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en");
|
||||
locale = NS_LITERAL_STRING("en");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
@@ -433,7 +389,6 @@ win32locale_test(void)
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
|
||||
delete locale;
|
||||
win32Locale->Release();
|
||||
}
|
||||
|
||||
@@ -455,152 +410,137 @@ win32locale_conversion_test(void)
|
||||
//
|
||||
// check english variants
|
||||
//
|
||||
locale = new nsString("en"); // generic english
|
||||
locale = NS_LITERAL_STRING("en"); // generic english
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-US"); // US english
|
||||
locale = NS_LITERAL_STRING("en-US"); // US english
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-GB"); // UK english
|
||||
locale = NS_LITERAL_STRING("en-GB"); // UK english
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_UK),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-CA"); // Canadian english
|
||||
locale = NS_LITERAL_STRING("en-CA"); // Canadian english
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_CAN),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// japanese
|
||||
//
|
||||
locale = new nsString("ja");
|
||||
locale = NS_LITERAL_STRING("ja");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_JAPANESE,SUBLANG_DEFAULT),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("ja-JP");
|
||||
locale = NS_LITERAL_STRING("ja-JP");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_JAPANESE,SUBLANG_DEFAULT),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// chinese Locales
|
||||
//
|
||||
locale = new nsString("zh");
|
||||
locale = NS_LITERAL_STRING("zh");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_DEFAULT),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("zh-CN");
|
||||
locale = NS_LITERAL_STRING("zh-CN");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("zh-TW");
|
||||
locale = NS_LITERAL_STRING("zh-TW");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_TRADITIONAL),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// german and variants
|
||||
//
|
||||
locale = new nsString("de");
|
||||
locale = NS_LITERAL_STRING("de");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_DEFAULT),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("de-DE");
|
||||
locale = NS_LITERAL_STRING("de-DE");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("de-AT");
|
||||
locale = NS_LITERAL_STRING("de-AT");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_GERMAN,SUBLANG_GERMAN_AUSTRIAN),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// french and it's variants
|
||||
//
|
||||
locale = new nsString("fr");
|
||||
locale = NS_LITERAL_STRING("fr");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_DEFAULT),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("fr-FR");
|
||||
locale = NS_LITERAL_STRING("fr-FR");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("fr-CA");
|
||||
locale = NS_LITERAL_STRING("fr-CA");
|
||||
loc_id = 0;
|
||||
|
||||
result = win32Locale->GetPlatformLocale(locale,&loc_id);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(loc_id==MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH_CANADIAN),SORT_DEFAULT),
|
||||
"nsLocaleTest: GetPlatformLocale failed.");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// delete the XPCOM inteface
|
||||
@@ -631,9 +571,9 @@ void
|
||||
win32_test_special_locales(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsIWin32Locale* win32Locale;
|
||||
nsILocale* xp_locale;
|
||||
nsILocaleFactory* xp_locale_factory;
|
||||
nsCOMPtr<nsIWin32Locale> win32Locale;
|
||||
nsCOMPtr<nsILocaleFactory> xp_locale_factory;
|
||||
nsCOMPtr<nsILocale> xp_locale;
|
||||
nsString* locale, *result_locale, *category;
|
||||
LCID sys_lcid, user_lcid;
|
||||
PRUnichar *lc_name_unichar;
|
||||
@@ -641,13 +581,11 @@ win32_test_special_locales(void)
|
||||
result = nsComponentManager::CreateInstance(kWin32LocaleFactoryCID,
|
||||
NULL,
|
||||
kIWin32LocaleIID,
|
||||
(void**)&win32Locale);
|
||||
NS_ASSERTION(win32Locale!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
getter_AddRefs(win32Locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
result = nsComponentManager::FindFactory(kLocaleFactoryCID,
|
||||
(nsIFactory**)&xp_locale_factory);
|
||||
NS_ASSERTION(xp_locale_factory!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
getter_AddRefs(xp_locale_factory));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
category = new nsString(localeCategoryList[0]);
|
||||
@@ -655,8 +593,7 @@ win32_test_special_locales(void)
|
||||
//
|
||||
// derive a system locale
|
||||
//
|
||||
result = xp_locale_factory->GetSystemLocale(&xp_locale);
|
||||
NS_ASSERTION(xp_locale!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
result = xp_locale_factory->GetSystemLocale(getter_AddRefs(xp_locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
sys_lcid = GetSystemDefaultLCID();
|
||||
@@ -665,19 +602,16 @@ win32_test_special_locales(void)
|
||||
|
||||
result = win32Locale->GetXPLocale(sys_lcid,locale);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
result = xp_locale->GetCategory(category->get(),&lc_name_unichar);
|
||||
result = xp_locale->GetCategory(category, &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
result_locale->SetString(lc_name_unichar);
|
||||
delete locale;
|
||||
delete result_locale;
|
||||
xp_locale->Release();
|
||||
|
||||
//
|
||||
// derive a system locale
|
||||
//
|
||||
result = xp_locale_factory->GetApplicationLocale(&xp_locale);
|
||||
NS_ASSERTION(xp_locale!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
result = xp_locale_factory->GetApplicationLocale(getter_AddRefs(xp_locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
user_lcid = GetUserDefaultLCID();
|
||||
@@ -686,18 +620,13 @@ win32_test_special_locales(void)
|
||||
|
||||
result = win32Locale->GetXPLocale(user_lcid,locale);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
result = xp_locale->GetCategory(category->get(),&lc_name_unichar);
|
||||
result = xp_locale->GetCategory(category, &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
result_locale->SetString(lc_name_unichar);
|
||||
delete locale;
|
||||
delete result_locale;
|
||||
xp_locale->Release();
|
||||
|
||||
delete category;
|
||||
xp_locale_factory->Release();
|
||||
win32Locale->Release();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -735,7 +664,7 @@ posixlocale_test(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsIPosixLocale* posix_locale;
|
||||
nsString* locale;
|
||||
nsAutoString locale;
|
||||
char posix_locale_string[9];
|
||||
|
||||
//
|
||||
@@ -751,29 +680,26 @@ posixlocale_test(void)
|
||||
//
|
||||
// test with a simple locale
|
||||
//
|
||||
locale = new nsString("en-US");
|
||||
locale = NS_LITERAL_STRING("en-US");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
NS_ASSERTION(strcmp("en_US",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// test with a not so simple locale
|
||||
//
|
||||
locale = new nsString("x-netscape");
|
||||
locale = NS_LITERAL_STRING("x-netscape");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
NS_ASSERTION(strcmp("C",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// test with a generic locale
|
||||
//
|
||||
locale = new nsString("en");
|
||||
locale = NS_LITERAL_STRING("en");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_string,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
NS_ASSERTION(strcmp("en",posix_locale_string)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
|
||||
//
|
||||
@@ -800,107 +726,92 @@ posixlocale_conversion_test()
|
||||
//
|
||||
// check english variants
|
||||
//
|
||||
locale = new nsString("en"); // generic english
|
||||
locale = NS_LITERAL_STRING("en"); // generic english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-US"); // US english
|
||||
locale = NS_LITERAL_STRING("en-US"); // US english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en_US",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-GB"); // UK english
|
||||
locale = NS_LITERAL_STRING("en-GB"); // UK english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en_GB",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("en-CA"); // Canadian english
|
||||
locale = NS_LITERAL_STRING("en-CA"); // Canadian english
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("en_CA",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// japanese
|
||||
//
|
||||
locale = new nsString("ja");
|
||||
locale = NS_LITERAL_STRING("ja");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("ja",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("ja-JP");
|
||||
locale = NS_LITERAL_STRING("ja-JP");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("ja_JP",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// chinese Locales
|
||||
//
|
||||
locale = new nsString("zh");
|
||||
locale = NS_LITERAL_STRING("zh");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("zh",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("zh-CN");
|
||||
locale = NS_LITERAL_STRING("zh-CN");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("zh_CN",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("zh-TW");
|
||||
locale = NS_LITERAL_STRING("zh-TW");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("zh_TW",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// german and variants
|
||||
//
|
||||
locale = new nsString("de");
|
||||
locale = NS_LITERAL_STRING("de");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("de",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("de-DE");
|
||||
locale = NS_LITERAL_STRING("de-DE");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("de_DE",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("de-AT");
|
||||
locale = NS_LITERAL_STRING("de-AT");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("de_AT",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// french and it's variants
|
||||
//
|
||||
locale = new nsString("fr");
|
||||
locale = NS_LITERAL_STRING("fr");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("fr",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("fr-FR");
|
||||
locale = NS_LITERAL_STRING("fr-FR");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("fr_FR",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
locale = new nsString("fr-CA");
|
||||
locale = NS_LITERAL_STRING("fr-CA");
|
||||
result = posix_locale->GetPlatformLocale(locale,posix_locale_result,9);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetPlatformLocale failed.");
|
||||
NS_ASSERTION(strcmp("fr_CA",posix_locale_result)==0,"nsLocaleTest: GetPlatformLocale failed.\n");
|
||||
delete locale;
|
||||
|
||||
//
|
||||
// delete the XPCOM inteface
|
||||
@@ -913,7 +824,7 @@ posixlocale_reverse_conversion_test()
|
||||
{
|
||||
nsresult result;
|
||||
nsIPosixLocale* posix_locale;
|
||||
nsString* locale;
|
||||
nsAutoString locale;
|
||||
|
||||
//
|
||||
// create the locale object
|
||||
@@ -928,23 +839,17 @@ posixlocale_reverse_conversion_test()
|
||||
//
|
||||
// test with a simple locale
|
||||
//
|
||||
locale = new nsString("");
|
||||
result = posix_locale->GetXPLocale("en_US",locale);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetXPLocale failed.\n");
|
||||
NS_ASSERTION(*locale=="en-US","nsLocaleTest: GetXPLocale failed.\n");
|
||||
delete locale;
|
||||
NS_ASSERTION(locale.Equals(NS_LITERAL_STRING("en-US")),"nsLocaleTest: GetXPLocale failed.\n");
|
||||
|
||||
locale = new nsString("");
|
||||
result = posix_locale->GetXPLocale("C",locale);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetXPLocale failed.\n");
|
||||
NS_ASSERTION(*locale=="en","nsLocaleTest: GetXPLocale failed.\n");
|
||||
delete locale;
|
||||
NS_ASSERTION(locale.Equals(NS_LITERAL_STRING("en")),"nsLocaleTest: GetXPLocale failed.\n");
|
||||
|
||||
locale = new nsString("");
|
||||
result = posix_locale->GetXPLocale("en",locale);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetXPLocale failed.\n");
|
||||
NS_ASSERTION(*locale=="en","nsLocaleTest: GetXPLocale failed.\n");
|
||||
delete locale;
|
||||
NS_ASSERTION(locale.Equals(NS_LITERAL_STRING("en")),"nsLocaleTest: GetXPLocale failed.\n");
|
||||
|
||||
posix_locale->Release();
|
||||
|
||||
@@ -954,8 +859,8 @@ void
|
||||
posixlocale_test_special(void)
|
||||
{
|
||||
nsresult result;
|
||||
nsILocaleFactory* xp_factory;
|
||||
nsILocale* xp_locale;
|
||||
nsCOMPtr<nsILocaleFactory> xp_factory;
|
||||
nsCOMPtr<nsILocale> xp_locale;
|
||||
const PRUnichar *lc_name_unichar;
|
||||
nsString* locale, *result_locale;
|
||||
nsString* lc_message;
|
||||
@@ -964,52 +869,42 @@ posixlocale_test_special(void)
|
||||
// create the locale objects
|
||||
//
|
||||
result = nsComponentManager::FindFactory(kLocaleFactoryCID,
|
||||
(nsIFactory**)&xp_factory);
|
||||
getter_AddRefs(xp_factory));
|
||||
|
||||
NS_ASSERTION(xp_factory!=NULL,"nsLocaleTest: factory_create_interface failed.");
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: factory_create_interface failed");
|
||||
|
||||
//
|
||||
// settup strings
|
||||
//
|
||||
locale = new nsString("en");
|
||||
locale = NS_LITERAL_STRING("en");
|
||||
result_locale = new nsString();
|
||||
lc_message = new nsString("NSILOCALE_MESSAGES");
|
||||
|
||||
//
|
||||
// test GetSystemLocale
|
||||
//
|
||||
result = xp_factory->GetSystemLocale(&xp_locale);
|
||||
NS_ASSERTION(xp_locale!=NULL,"nsLocaleTest: GetSystemLocale failed.\n");
|
||||
result = xp_factory->GetSystemLocale(getter_AddRefs(xp_locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetSystemLocale failed.\n");
|
||||
|
||||
result = xp_locale->GetCategory(lc_message->get(),&lc_name_unichar);
|
||||
NS_ASSERTION(*result_locale==*locale,"nsLocaleTest: GetSystemLocale failed.\n");
|
||||
result = xp_locale->GetCategory(lc_message, &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetSystemLocale failed.\n");
|
||||
|
||||
result_locale->SetString(lc_name_unichar);
|
||||
xp_locale->Release();
|
||||
|
||||
result = xp_factory->GetApplicationLocale(&xp_locale);
|
||||
NS_ASSERTION(xp_locale!=NULL,"nsLocaleTest: GetApplicationLocale failed.\n");
|
||||
result = xp_factory->GetApplicationLocale(getter_AddRefs(xp_locale));
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetApplicationLocale failed.\n");
|
||||
|
||||
|
||||
result = xp_locale->GetCategory(lc_message->get(),&lc_name_unichar);
|
||||
NS_ASSERTION(*result_locale==*locale,"nsLocaleTest: GetSystemLocale failed.\n");
|
||||
result = xp_locale->GetCategory(lc_message, &lc_name_unichar);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: GetSystemLocale failed.\n");
|
||||
result_locale->SetString(lc_name_unichar);
|
||||
xp_locale->Release();
|
||||
|
||||
//
|
||||
// delete strings
|
||||
//
|
||||
delete locale;
|
||||
delete result_locale;
|
||||
delete lc_message;
|
||||
|
||||
xp_factory->Release();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -68,35 +68,21 @@
|
||||
//
|
||||
//
|
||||
nsresult
|
||||
getCountry(PRUnichar *lc_name_unichar, PRUnichar **aCountry)
|
||||
getCountry(const nsAString &lc_name, nsAString &aCountry)
|
||||
{
|
||||
|
||||
nsresult result = NS_OK;
|
||||
nsAutoString category(NS_LITERAL_STRING("NSILOCALE_MESSAGES"));
|
||||
|
||||
nsAutoString lc_name;
|
||||
lc_name.Assign(lc_name_unichar);
|
||||
// nsMemory::Free(lc_name_unichar);
|
||||
|
||||
PRInt32 dash = lc_name.FindChar('-');
|
||||
if (dash > 0) {
|
||||
/*
|
||||
*/
|
||||
nsAutoString lang;
|
||||
nsAutoString country;
|
||||
PRInt32 count = 0;
|
||||
count = lc_name.Left(lang, dash);
|
||||
count = lc_name.Right(country, (lc_name.Length()-dash-1));
|
||||
*aCountry = ToNewUnicode(country);
|
||||
aCountry = lc_name;
|
||||
aCountry.Cut(dash, (lc_name.Length()-dash-1));
|
||||
}
|
||||
else
|
||||
result = NS_ERROR_FAILURE;
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
getUILangCountry(PRUnichar** aUILang, PRUnichar** aCountry)
|
||||
getUILangCountry(nsAString& aUILang, nsAString& aCountry)
|
||||
{
|
||||
nsresult result;
|
||||
// get a locale service
|
||||
@@ -104,7 +90,8 @@ getUILangCountry(PRUnichar** aUILang, PRUnichar** aCountry)
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: get locale service failed");
|
||||
|
||||
result = localeService->GetLocaleComponentForUserAgent(aUILang);
|
||||
result = getCountry(*aUILang, aCountry);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: get locale component failed");
|
||||
result = getCountry(aUILang, aCountry);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -127,14 +114,12 @@ main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
PRUnichar *uiLang = nsnull;
|
||||
PRUnichar *country = nsnull;
|
||||
ret = getUILangCountry(&uiLang, &country);
|
||||
nsAutoString uiLang;
|
||||
nsAutoString country;
|
||||
ret = getUILangCountry(uiLang, country);
|
||||
#if DEBUG_tao
|
||||
nsAutoString uaStr(uiLang); // testing only
|
||||
nsAutoString countryStr(country); // testing only
|
||||
cout << "\n uaStr=" << ToNewCString(uaStr)
|
||||
<< ", country=" << ToNewCString(countryStr)
|
||||
cout << "\n uiLang=" << NS_LossyConvertUTF16toASCII(uiLang).get()
|
||||
<< ", country=" << NS_LossyConvertUTF16toASCII(country).get()
|
||||
<< "\n" << endl;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
|
||||
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsACString& oResult) = 0;
|
||||
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACString& oResult) = 0;
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, nsACString& aResult
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACString& aResult)
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& aResult)
|
||||
{
|
||||
aResult = mCharset;
|
||||
return NS_OK;
|
||||
@@ -90,9 +90,9 @@ nsPlatformCharset::InitGetCharset(nsACString &aString)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& aResult)
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& aResult)
|
||||
{
|
||||
CopyASCIItoUCS2(mCharset, aResult);
|
||||
aResult = mCharset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,15 +154,14 @@ nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, nsACString& oResult
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACString &oResult)
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString &oResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMacLocale> pMacLocale;
|
||||
pMacLocale = do_CreateInstance(NS_MACLOCALE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAutoString localeAsString(localeName);
|
||||
short script, language, region;
|
||||
rv = pMacLocale->GetPlatformLocale(&localeAsString, &script, &language, ®ion);
|
||||
rv = pMacLocale->GetPlatformLocale(localeName, &script, &language, ®ion);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (NS_SUCCEEDED(MapToCharset(script, region, oResult))) {
|
||||
return NS_OK;
|
||||
@@ -194,7 +193,7 @@ nsPlatformCharset::InitGetCharset(nsACString &oString)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& oResult)
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& oResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharse
|
||||
return rv;
|
||||
}
|
||||
|
||||
CopyUCS2toASCII(charset, outCharset);
|
||||
LossyCopyUTF16toASCII(charset, outCharset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACString &oResult)
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString &oResult)
|
||||
{
|
||||
oResult.Truncate();
|
||||
return NS_OK;
|
||||
@@ -159,7 +159,7 @@ nsPlatformCharset::InitGetCharset(nsACString &oString)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& oResult)
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& oResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
|
||||
NS_IMETHOD Init();
|
||||
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsACString& oResult);
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACString& oResult);
|
||||
NS_IMETHOD GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult);
|
||||
|
||||
private:
|
||||
nsCString mCharset;
|
||||
@@ -61,7 +61,7 @@ private:
|
||||
nsresult MapToCharset(short script, short region, nsACString& outCharset);
|
||||
nsresult MapToCharset(nsAString& inANSICodePage, nsACString& outCharset);
|
||||
nsresult InitGetCharset(nsACString& oString);
|
||||
nsresult ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& oResult);
|
||||
nsresult ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& oResult);
|
||||
nsresult VerifyCharset(nsCString &aCharset);
|
||||
};
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include "nsPlatformCharset.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "prinit.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
|
||||
|
||||
@@ -89,7 +90,7 @@ nsPlatformCharset::nsPlatformCharset()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& oResult)
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& oResult)
|
||||
{
|
||||
|
||||
// locked for thread safety
|
||||
@@ -108,23 +109,26 @@ nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& loc
|
||||
platformLocaleKey.Assign(NS_LITERAL_STRING("locale."));
|
||||
platformLocaleKey.AppendWithConversion(OSTYPE);
|
||||
platformLocaleKey.Append(NS_LITERAL_STRING("."));
|
||||
platformLocaleKey.Append(locale.get());
|
||||
platformLocaleKey.Append(locale);
|
||||
|
||||
nsresult res = gInfo_deprecated->Get(platformLocaleKey, oResult);
|
||||
nsAutoString charset;
|
||||
nsresult res = gInfo_deprecated->Get(platformLocaleKey, charset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
LossyCopyUTF16toASCII(charset, oResult);
|
||||
return NS_OK;
|
||||
}
|
||||
nsAutoString localeKey;
|
||||
localeKey.Assign(NS_LITERAL_STRING("locale.all."));
|
||||
localeKey.Append(locale.get());
|
||||
res = gInfo_deprecated->Get(localeKey, oResult);
|
||||
localeKey.Append(locale);
|
||||
res = gInfo_deprecated->Get(localeKey, charset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
LossyCopyUTF16toASCII(charset, oResult);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
NS_ASSERTION(0, "unable to convert locale to charset using deprecated config");
|
||||
mCharset.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
|
||||
oResult.Assign(NS_LITERAL_STRING("ISO-8859-1"));
|
||||
oResult.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
|
||||
return NS_SUCCESS_USING_FALLBACK_LOCALE;
|
||||
}
|
||||
|
||||
@@ -153,17 +157,16 @@ nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, nsACString& oResult
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACString &oResult)
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString &oResult)
|
||||
{
|
||||
nsAutoString localeNameAsString(localeName);
|
||||
|
||||
//
|
||||
// if this locale is the user's locale then use the charset
|
||||
// we already determined at initialization
|
||||
//
|
||||
if (mLocale.Equals(localeNameAsString) ||
|
||||
if (mLocale.Equals(localeName) ||
|
||||
// support the 4.x behavior
|
||||
(mLocale.EqualsIgnoreCase("en_US") && localeNameAsString.EqualsIgnoreCase("C"))) {
|
||||
(mLocale.EqualsIgnoreCase("en_US") &&
|
||||
localeName.Equals(NS_LITERAL_STRING("C"),nsCaseInsensitiveStringComparator()))) {
|
||||
oResult = mCharset;
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -191,12 +194,9 @@ nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACS
|
||||
// using the deprecated locale to charset mapping
|
||||
//
|
||||
nsAutoString localeStr(localeName);
|
||||
nsAutoString charset;
|
||||
nsresult res = ConvertLocaleToCharsetUsingDeprecatedConfig(localeStr, charset);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
LossyCopyUTF16toASCII(charset, oResult); // charset name is always ASCII.
|
||||
return res; // succeeded
|
||||
}
|
||||
nsresult res = ConvertLocaleToCharsetUsingDeprecatedConfig(localeStr, oResult);
|
||||
if (NS_SUCCEEDED(res))
|
||||
return res;
|
||||
|
||||
NS_ASSERTION(0, "unable to convert locale to charset using deprecated config");
|
||||
oResult.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
|
||||
@@ -306,13 +306,12 @@ nsPlatformCharset::InitGetCharset(nsACString &oString)
|
||||
char* locale = setlocale(LC_CTYPE, nsnull);
|
||||
nsAutoString localeStr;
|
||||
localeStr.AssignWithConversion(locale);
|
||||
nsAutoString uCharset;
|
||||
res = ConvertLocaleToCharsetUsingDeprecatedConfig(localeStr, uCharset);
|
||||
res = ConvertLocaleToCharsetUsingDeprecatedConfig(localeStr, oString);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
CopyUCS2toASCII(uCharset, oString);
|
||||
return res; // succeeded
|
||||
}
|
||||
|
||||
oString.Truncate();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,8 @@ nsPlatformCharset::nsPlatformCharset()
|
||||
{
|
||||
NS_TIMELINE_START_TIMER("nsPlatformCharset()");
|
||||
|
||||
UINT acp = ::GetACP();
|
||||
PRInt32 acpint = (PRInt32)(acp & 0x00FFFF);
|
||||
nsAutoString acpKey(NS_LITERAL_STRING("acp."));
|
||||
acpKey.AppendInt(acpint, 10);
|
||||
acpKey.AppendInt(PRInt32(::GetACP() & 0x00FFFF), 10);
|
||||
nsresult res = MapToCharset(acpKey, mCharset);
|
||||
|
||||
NS_TIMELINE_STOP_TIMER("nsPlatformCharset()");
|
||||
@@ -132,12 +130,11 @@ nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACString& oResult)
|
||||
nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString& oResult)
|
||||
{
|
||||
nsCOMPtr<nsIWin32Locale> winLocale;
|
||||
LCID localeAsLCID;
|
||||
char acp_name[6];
|
||||
nsAutoString localeAsNSString(localeName);
|
||||
|
||||
//
|
||||
// convert locale name to a code page (through the LCID)
|
||||
@@ -148,13 +145,13 @@ nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, nsACS
|
||||
winLocale = do_CreateInstance(NS_WIN32LOCALE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) { return rv; }
|
||||
|
||||
rv = winLocale->GetPlatformLocale(&localeAsNSString, &localeAsLCID);
|
||||
rv = winLocale->GetPlatformLocale(localeName, &localeAsLCID);
|
||||
if (NS_FAILED(rv)) { return rv; }
|
||||
|
||||
if (GetLocaleInfo(localeAsLCID, LOCALE_IDEFAULTANSICODEPAGE, acp_name, sizeof(acp_name))==0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsAutoString acp_key; acp_key.Assign(NS_LITERAL_STRING("acp."));
|
||||
nsAutoString acp_key(NS_LITERAL_STRING("acp."));
|
||||
acp_key.AppendWithConversion(acp_name);
|
||||
|
||||
return MapToCharset(acp_key, oResult);
|
||||
@@ -179,7 +176,7 @@ nsPlatformCharset::InitGetCharset(nsACString &oString)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& oResult)
|
||||
nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& oResult)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -50,35 +50,35 @@ NS_DEFINE_IID(kPlatformCharsetIID,NS_IPLATFORMCHARSET_IID);
|
||||
int
|
||||
main(int argc, const char** argv)
|
||||
{
|
||||
nsCOMPtr<nsILocaleService> locale_service;
|
||||
|
||||
nsCOMPtr<nsIPlatformCharset> platform_charset =
|
||||
do_CreateInstance(NS_PLATFORMCHARSET_CONTRACTID);
|
||||
if (!platform_charset) return -1;
|
||||
|
||||
nsCOMPtr<nsILocaleService> locale_service =
|
||||
do_CreateInstance(kLocaleServiceCID);
|
||||
if (!locale_service) return -1;
|
||||
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
nsCOMPtr<nsIPlatformCharset> platform_charset;
|
||||
nsString locale_category(NS_LITERAL_STRING("NSILOCALE_MESSAGES"));
|
||||
PRUnichar* category_value;
|
||||
nsCAutoString charset;
|
||||
nsString categoryAsNSString;
|
||||
nsAutoString category;
|
||||
|
||||
nsresult rv = nsComponentManager::CreateInstance(NS_PLATFORMCHARSET_CONTRACTID, NULL, kPlatformCharsetIID, getter_AddRefs(platform_charset));
|
||||
rv = nsComponentManager::CreateInstance(kLocaleServiceCID, NULL, kLocaleServiceIID, getter_AddRefs(locale_service));
|
||||
nsresult rv = locale_service->GetSystemLocale(getter_AddRefs(locale));
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = locale_service->GetSystemLocale(getter_AddRefs(locale));
|
||||
rv = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_MESSAGES"), category);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = locale->GetCategory(locale_category.get(), &category_value);
|
||||
rv = platform_charset->GetDefaultCharsetForLocale(category, charset);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = platform_charset->GetDefaultCharsetForLocale(category_value, charset);
|
||||
printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(category).get(), charset.get());
|
||||
|
||||
category.Assign(NS_LITERAL_STRING("en-US"));
|
||||
rv = platform_charset->GetDefaultCharsetForLocale(category, charset);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
categoryAsNSString = category_value;
|
||||
printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(categoryAsNSString).get(), charset.get());
|
||||
|
||||
categoryAsNSString.Assign(NS_LITERAL_STRING("en-US"));
|
||||
rv = platform_charset->GetDefaultCharsetForLocale(categoryAsNSString.get(), charset);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(categoryAsNSString).get(), charset.get());
|
||||
printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(category).get(), charset.get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1863,8 +1863,8 @@ QuotingOutputStreamListener::QuotingOutputStreamListener(const char * originalMs
|
||||
nsCOMPtr<nsILocaleService> localeService(do_GetService(NS_LOCALESERVICE_CONTRACTID));
|
||||
|
||||
// Format date using "mailnews.reply_header_locale", if empty then use application default locale.
|
||||
if (replyHeaderLocale && *replyHeaderLocale)
|
||||
rv = localeService->NewLocale(replyHeaderLocale.get(), getter_AddRefs(locale));
|
||||
if (!replyHeaderLocale.IsEmpty())
|
||||
rv = localeService->NewLocale(replyHeaderLocale, getter_AddRefs(locale));
|
||||
else
|
||||
rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
|
||||
|
||||
|
||||
@@ -839,9 +839,8 @@ getUILangCountry(nsAString& aUILang, nsAString& aCountry)
|
||||
nsCOMPtr<nsILocaleService> localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &result);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result),"getUILangCountry: get locale service failed");
|
||||
|
||||
nsXPIDLString uiLang;
|
||||
result = localeService->GetLocaleComponentForUserAgent(getter_Copies(uiLang));
|
||||
aUILang = uiLang;
|
||||
result = localeService->GetLocaleComponentForUserAgent(aUILang);
|
||||
NS_ASSERTION(NS_SUCCEEDED(result), "getUILangCountry: get locale component failed");
|
||||
result = getCountry(aUILang, aCountry);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -689,7 +689,7 @@ function getStringBundle()
|
||||
const lsContractID = "@mozilla.org/intl/nslocaleservice;1";
|
||||
const lsIID = Components.interfaces.nsILocaleService;
|
||||
const ls = Components.classes[lsContractID].getService(lsIID);
|
||||
var appLocale = ls.GetApplicationLocale();
|
||||
var appLocale = ls.getApplicationLocale();
|
||||
return sbs.createBundle(bundleURL, appLocale);
|
||||
}
|
||||
|
||||
|
||||
@@ -1038,9 +1038,9 @@ var BookmarksUtils = {
|
||||
var BUNDLESVC = Components.classes["@mozilla.org/intl/stringbundle;1"]
|
||||
.getService(Components.interfaces.nsIStringBundleService);
|
||||
var bookmarksBundle = "chrome://communicator/locale/bookmarks/bookmarks.properties";
|
||||
this._bundle = BUNDLESVC.createBundle(bookmarksBundle, LOCALESVC.GetApplicationLocale());
|
||||
this._bundle = BUNDLESVC.createBundle(bookmarksBundle, LOCALESVC.getApplicationLocale());
|
||||
var brandBundle = "chrome://global/locale/brand.properties";
|
||||
this._brandShortName = BUNDLESVC.createBundle(brandBundle, LOCALESVC.GetApplicationLocale())
|
||||
this._brandShortName = BUNDLESVC.createBundle(brandBundle, LOCALESVC.getApplicationLocale())
|
||||
.GetStringFromName("brandShortName");
|
||||
}
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@
|
||||
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
|
||||
.getService(Components.interfaces.nsIStringBundleService);
|
||||
var bundleURL = "chrome://global/locale/tabbrowser.properties";
|
||||
this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
|
||||
this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.getApplicationLocale());
|
||||
}
|
||||
return this._mStrBundle;
|
||||
]]></getter>
|
||||
|
||||
@@ -152,7 +152,7 @@
|
||||
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
|
||||
.getService(Components.interfaces.nsIStringBundleService);
|
||||
var bundleURL = "chrome://global/locale/dialog.properties";
|
||||
this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
|
||||
this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.getApplicationLocale());
|
||||
}
|
||||
return this._mStrBundle;
|
||||
]]></getter>
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
try {
|
||||
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
|
||||
.getService(Components.interfaces.nsILocaleService);
|
||||
return localeService.GetApplicationLocale();
|
||||
return localeService.getApplicationLocale();
|
||||
}
|
||||
catch (ex) {
|
||||
return null;
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
.getService(Components.interfaces.nsILocaleService);
|
||||
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
|
||||
var bundleURL = "chrome://global-platform/locale/wizard.properties";
|
||||
this._bundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
|
||||
this._bundle = stringBundleService.createBundle(bundleURL, localeService.getApplicationLocale());
|
||||
|
||||
// get anonymous content references
|
||||
this._wizardHeader = document.getAnonymousElementByAttribute(this, "anonid", "Header");
|
||||
|
||||
Reference in New Issue
Block a user