author | Zibi Braniecki <zbraniecki@mozilla.com> |
Thu, 03 Aug 2017 02:33:51 -0700 | |
changeset 620663 | dc259fce2a6710297883e0bf4ae1dead4547cb93 |
parent 620494 | fa1da3c0b200abbd9cfab3cab19962824314044e |
child 640782 | 96ef870a288b80a054e4345c29c1343ab396a690 |
push id | 72127 |
push user | bmo:gandalf@aviary.pl |
push date | Thu, 03 Aug 2017 19:41:15 +0000 |
reviewers | m_kato |
bugs | 1356263 |
milestone | 57.0a1 |
--- a/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp +++ b/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp @@ -1,35 +1,37 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:set ts=2 sw=2 sts=2 et cindent: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsILocaleService.h" #include "nsISpeechService.h" #include "nsServiceManagerUtils.h" #include "nsCategoryManagerUtils.h" #include "MediaPrefs.h" #include "SpeechSynthesisUtterance.h" #include "SpeechSynthesisVoice.h" #include "nsSynthVoiceRegistry.h" #include "nsSpeechTask.h" #include "AudioChannelService.h" #include "nsString.h" #include "mozilla/StaticPtr.h" #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentParent.h" +#include "mozilla/intl/LocaleService.h" #include "mozilla/Unused.h" #include "SpeechSynthesisChild.h" #include "SpeechSynthesisParent.h" +using mozilla::intl::LocaleService; + #undef LOG extern mozilla::LogModule* GetSpeechSynthLog(); #define LOG(type, msg) MOZ_LOG(GetSpeechSynthLog(), type, msg) namespace { void GetAllSpeechSynthActors(InfallibleTArray<mozilla::dom::SpeechSynthesisParent*>& aActors) @@ -612,32 +614,23 @@ nsSynthVoiceRegistry::FindBestMatch(cons NS_ConvertUTF16toUTF8(aLang).get(), NS_ConvertUTF16toUTF8(retval->mLang).get())); return retval; } } // Try UI language. - nsresult rv; - nsCOMPtr<nsILocaleService> localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } + nsAutoCString uiLang; + LocaleService::GetInstance()->GetAppLocaleAsLangTag(uiLang); - nsAutoString uiLang; - rv = localeService->GetLocaleComponentForUserAgent(uiLang); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - - if (FindVoiceByLang(uiLang, &retval)) { + if (FindVoiceByLang(NS_ConvertASCIItoUTF16(uiLang), &retval)) { LOG(LogLevel::Debug, ("nsSynthVoiceRegistry::FindBestMatch - Matched UI language (%s ~= %s)", - NS_ConvertUTF16toUTF8(uiLang).get(), + uiLang.get(), NS_ConvertUTF16toUTF8(retval->mLang).get())); return retval; } // Try en-US, the language of locale "C" if (FindVoiceByLang(NS_LITERAL_STRING("en-US"), &retval)) { LOG(LogLevel::Debug,
--- a/intl/build/nsI18nModule.cpp +++ b/intl/build/nsI18nModule.cpp @@ -38,33 +38,31 @@ NS_DEFINE_NAMED_CID(MOZ_LOCALESERVICE_CI NS_DEFINE_NAMED_CID(MOZ_OSPREFERENCES_CID); NS_DEFINE_NAMED_CID(NS_LBRK_CID); NS_DEFINE_NAMED_CID(NS_WBRK_CID); NS_DEFINE_NAMED_CID(NS_ENTITYCONVERTER_CID); NS_DEFINE_NAMED_CID(NS_SAVEASCHARSET_CID); NS_DEFINE_NAMED_CID(NS_UNICODE_NORMALIZER_CID); NS_DEFINE_NAMED_CID(NS_STRINGBUNDLESERVICE_CID); NS_DEFINE_NAMED_CID(NS_STRINGBUNDLETEXTOVERRIDE_CID); -NS_DEFINE_NAMED_CID(NS_LOCALESERVICE_CID); NS_DEFINE_NAMED_CID(NS_COLLATIONFACTORY_CID); NS_DEFINE_NAMED_CID(NS_SCRIPTABLEDATEFORMAT_CID); NS_DEFINE_NAMED_CID(NS_PLATFORMCHARSET_CID); NS_DEFINE_NAMED_CID(NS_COLLATION_CID); static const mozilla::Module::CIDEntry kIntlCIDs[] = { { &kMOZ_LOCALESERVICE_CID, false, nullptr, mozilla::intl::LocaleServiceConstructor }, { &kMOZ_OSPREFERENCES_CID, false, nullptr, mozilla::intl::OSPreferencesConstructor }, { &kNS_LBRK_CID, false, nullptr, nsJISx4051LineBreakerConstructor }, { &kNS_WBRK_CID, false, nullptr, nsSampleWordBreakerConstructor }, { &kNS_ENTITYCONVERTER_CID, false, nullptr, nsEntityConverterConstructor }, { &kNS_SAVEASCHARSET_CID, false, nullptr, nsSaveAsCharsetConstructor }, { &kNS_UNICODE_NORMALIZER_CID, false, nullptr, nsUnicodeNormalizerConstructor }, { &kNS_STRINGBUNDLESERVICE_CID, false, nullptr, nsStringBundleServiceConstructor }, { &kNS_STRINGBUNDLETEXTOVERRIDE_CID, false, nullptr, nsStringBundleTextOverrideConstructor }, - { &kNS_LOCALESERVICE_CID, false, nullptr, CreateLocaleService }, { &kNS_COLLATIONFACTORY_CID, false, nullptr, nsCollationFactoryConstructor }, { &kNS_SCRIPTABLEDATEFORMAT_CID, false, nullptr, NS_NewScriptableDateFormat }, { &kNS_PLATFORMCHARSET_CID, false, nullptr, nsPlatformCharsetConstructor }, { &kNS_COLLATION_CID, false, nullptr, nsCollationConstructor }, { nullptr } }; static const mozilla::Module::ContractIDEntry kIntlContracts[] = { @@ -72,17 +70,16 @@ static const mozilla::Module::ContractID { MOZ_OSPREFERENCES_CONTRACTID, &kMOZ_OSPREFERENCES_CID }, { NS_LBRK_CONTRACTID, &kNS_LBRK_CID }, { NS_WBRK_CONTRACTID, &kNS_WBRK_CID }, { NS_ENTITYCONVERTER_CONTRACTID, &kNS_ENTITYCONVERTER_CID }, { NS_SAVEASCHARSET_CONTRACTID, &kNS_SAVEASCHARSET_CID }, { NS_UNICODE_NORMALIZER_CONTRACTID, &kNS_UNICODE_NORMALIZER_CID }, { NS_STRINGBUNDLE_CONTRACTID, &kNS_STRINGBUNDLESERVICE_CID }, { NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID, &kNS_STRINGBUNDLETEXTOVERRIDE_CID }, - { NS_LOCALESERVICE_CONTRACTID, &kNS_LOCALESERVICE_CID }, { NS_COLLATIONFACTORY_CONTRACTID, &kNS_COLLATIONFACTORY_CID }, { NS_SCRIPTABLEDATEFORMAT_CONTRACTID, &kNS_SCRIPTABLEDATEFORMAT_CID }, { NS_PLATFORMCHARSET_CONTRACTID, &kNS_PLATFORMCHARSET_CID }, { NS_COLLATION_CONTRACTID, &kNS_COLLATION_CID }, { nullptr } }; static const mozilla::Module kIntlModule = {
--- a/intl/locale/moz.build +++ b/intl/locale/moz.build @@ -18,56 +18,43 @@ else: DIRS += ['gtk'] elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android': DIRS += ['android'] XPIDL_SOURCES += [ 'mozILocaleService.idl', 'mozIOSPreferences.idl', 'nsICollation.idl', - 'nsILocale.idl', - 'nsILocaleService.idl', 'nsIScriptableDateFormat.idl', ] XPIDL_MODULE = 'locale' EXPORTS += [ 'DateTimeFormat.h', 'nsCollationCID.h', 'nsIPlatformCharset.h', 'nsLanguageAtomService.h', - 'nsPosixLocale.h', 'nsUConvPropertySearch.h', - 'nsWin32Locale.h', ] EXPORTS.mozilla.intl += [ 'LocaleService.h', 'OSPreferences.h', ] UNIFIED_SOURCES += [ 'LocaleService.cpp', 'nsCollationFactory.cpp', 'nsLanguageAtomService.cpp', - 'nsLocale.cpp', 'nsScriptableDateFormat.cpp', 'nsUConvPropertySearch.cpp', 'OSPreferences.cpp', ] -# This file includes Carbon.h, which pulls -# in CoreServices on OSX. This requires -# a TextRange struct, which clashes with mozilla::TextRange, -# because of a `using namespace mozilla;` somewhere -# in the unified build -SOURCES += [ - 'nsLocaleService.cpp', -] if CONFIG['ENABLE_INTL_API']: UNIFIED_SOURCES += [ 'DateTimeFormat.cpp', 'nsCollation.cpp', ] else: UNIFIED_SOURCES += [
--- a/intl/locale/nsICollation.idl +++ b/intl/locale/nsICollation.idl @@ -1,14 +1,14 @@ /* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsILocale.idl" +#include "nsISupports.idl" interface nsICollation; [scriptable, uuid(04971e14-d6b3-4ada-8cbb-c3a13842b349)] interface nsICollationFactory : nsISupports { /** * Create a new collation for the current application locale.
deleted file mode 100644 --- a/intl/locale/nsILocale.idl +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsISupports.idl" - -%{C++ -#define NSILOCALE_COLLATE "NSILOCALE_COLLATE" -#define NSILOCALE_CTYPE "NSILOCALE_CTYPE" -#define NSILOCALE_MONETARY "NSILOCALE_MONETARY" -#define NSILOCALE_NUMERIC "NSILOCALE_NUMERIC" -#define NSILOCALE_TIME "NSILOCALE_TIME" -#define NSILOCALE_MESSAGE "NSILOCALE_MESSAGES" - -#define NS_LOCALE_CONTRACTID "@mozilla.org/intl/nslocale;1" -%} - -/** - * Represents one locale, which can be used for things like sorting text strings - * and formatting numbers, dates and times. - */ -[scriptable, uuid(21035ee0-4556-11d3-91cd-00105aa3f7dc)] -interface nsILocale : nsISupports -{ - /** - * Get the locale code for a given category. - * - * A locale code is of the form language[-COUNTRY[-region]], where - * "language" is an ISO 639 language code (two letter codes preferred over - * three letter codes when available), "COUNTRY" is an ISO 3166 two letter - * country code, and "region" is a string of up to 5 letters. - * - * A category is one of the following: - * NSILOCALE_CTYPE: Character classification and case conversion. - * NSILOCALE_COLLATE: Collation order. How strings are sorted. - * NSILOCALE_MONETARY: Monetary formatting. - * NSILOCALE_NUMERIC: Numeric, non-monetary formatting. - * NSILOCALE_TIME: Date and time formats. - * NSILOCALE_MESSAGES: Related to fonts, character encodings etc. - * - * @param category - * The category of interest. - * @return The locale code to be used for the given category. - */ - AString getCategory(in AString category); -};
deleted file mode 100644 --- a/intl/locale/nsILocaleService.idl +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsISupports.idl" -#include "nsILocale.idl" - -/** - * The Locale service interface. This is a singleton object, and should be - * obtained from the <tt>nsServiceManager</tt>. - */ -[scriptable, uuid(c2edc848-4219-4440-abbf-98119882c83f)] -interface nsILocaleService : nsISupports -{ - /** - * Create a new nsILocale from a locale string. - * - * @param aLocale - * A locale code as described in nsILocale. - * @return A nsILocale representing the given locale. - */ - nsILocale newLocale(in AString aLocale); - - /** - * Get the user preference for locale from the operating system. - * - * @return User's OS setting for preferred locale. - */ - nsILocale getSystemLocale(); - - /** - * Get the user preference for locale from the operating system. - * - * NOTE: This has nothing to do with the locale used for localization of - * the application (UI text strings etc.). This method returns something - * similar to getSystemLocale. - * - * @return User's OS setting for preferred locale. - */ - nsILocale getApplicationLocale(); - - /** - * Get the most preferred locale from a list of locale preferences. - * - * @param acceptLanguage - * Locale preference in the same format as the Accept-Language HTTP - * header. - * @return The most preferred locale according to the acceptLanguage - * parameter. - */ - nsILocale getLocaleFromAcceptLanguage(in string acceptLanguage); - - /** - * Get the user preference for locale from the operating system. - * - * NOTE: This has nothing to do with any HTTP User-Agent. This method - * returns the same as getSystemLocale, but as a string. - * - * @return User's OS setting for preferred locale in the format described - * in nsILocale. - */ - AString getLocaleComponentForUserAgent(); -}; - -%{C++ - -// {C8E518C1-47AE-11d3-91CD-00105AA3F7DC} -#define NS_LOCALESERVICE_CID {0xc8e518c1,0x47ae,0x11d3,{0x91,0xcd,0x0,0x10,0x5a,0xa3,0xf7,0xdc}} -#define NS_LOCALESERVICE_CONTRACTID "@mozilla.org/intl/nslocaleservice;1" - -extern nsresult -NS_NewLocaleService(nsILocaleService** result); - -%} - -
--- a/intl/locale/nsIScriptableDateFormat.idl +++ b/intl/locale/nsIScriptableDateFormat.idl @@ -115,19 +115,19 @@ interface nsIScriptableDateFormat : nsIS /** * Format the given date and time in a human readable format. * * The underlying operating system is used to format the date and time. * * Pass an empty string as the locale parameter to use the OS settings with * the preferred date and time formatting given by the user. * - * Pass a locale code as described in nsILocale as the locale parameter - * (e.g. en-US) to use a specific locale. If the given locale is not - * available, a fallback will be used. + * Pass a locale code as described in nsILocaleService as the locale + * parameter (e.g. en-US) to use a specific locale. If the given locale + * is not available, a fallback will be used. * * NOTE: The output of this method depends on the operating system and user * settings. Even if you pass a locale code as the first parameter, there * are no guarantees about which locale and exact format the returned value * uses. Even if you know the locale, the format might be customized by the * user. Therefore you should not use the returned values in contexts where * you depend on any specific format or language. *
deleted file mode 100644 --- a/intl/locale/nsLocale.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsString.h" -#include "nsISupports.h" -#include "nsILocale.h" -#include "nsLocale.h" -#include "nsMemory.h" -#include "nsCRT.h" - -#define LOCALE_HASH_SIZE 0xFF - - -/* nsILocale */ -NS_IMPL_ISUPPORTS(nsLocale, nsILocale) - -nsLocale::nsLocale(void) -: fHashtable(nullptr), fCategoryCount(0) -{ - fHashtable = PL_NewHashTable(LOCALE_HASH_SIZE,&nsLocale::Hash_HashFunction, - &nsLocale::Hash_CompareNSString, - &nsLocale::Hash_CompareNSString, - nullptr, nullptr); - NS_ASSERTION(fHashtable, "nsLocale: failed to allocate PR_Hashtable"); -} - -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, - nullptr); - - PL_HashTableDestroy(fHashtable); -} - -NS_IMETHODIMP -nsLocale::GetCategory(const nsAString& category, nsAString& result) -{ - const char16_t *value = (const char16_t*) - PL_HashTableLookup(fHashtable, PromiseFlatString(category).get()); - - if (value) - { - result.Assign(value); - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsLocale::AddCategory(const nsAString &category, const nsAString &value) -{ - char16_t* newKey = ToNewUnicode(category); - if (!newKey) - return NS_ERROR_OUT_OF_MEMORY; - - char16_t* newValue = ToNewUnicode(value); - if (!newValue) { - free(newKey); - return NS_ERROR_OUT_OF_MEMORY; - } - - if (!PL_HashTableAdd(fHashtable, newKey, newValue)) { - free(newKey); - free(newValue); - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - - -PLHashNumber -nsLocale::Hash_HashFunction(const void* key) -{ - const char16_t* ptr = (const char16_t *) key; - PLHashNumber hash; - - hash = (PLHashNumber)0; - - while (*ptr) - hash += (PLHashNumber) *ptr++; - - return hash; -} - - -int -nsLocale::Hash_CompareNSString(const void* s1, const void* s2) -{ - return !nsCRT::strcmp((const char16_t *) s1, (const char16_t *) s2); -} - - -int -nsLocale::Hash_EnumerateDelete(PLHashEntry *he, int hashIndex, void *arg) -{ - // delete an entry - free((char16_t *)he->key); - free((char16_t *)he->value); - - return (HT_ENUMERATE_NEXT | HT_ENUMERATE_REMOVE); -} -
deleted file mode 100644 --- a/intl/locale/nsLocale.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * This Original Code has been modified by IBM Corporation. - * Modifications made by IBM described herein are - * Copyright (c) International Business Machines - * Corporation, 2000 - * - * Modifications to Mozilla code or documentation - * identified per MPL Section 3.3 - * - * Date Modified by Description of modification - * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink - * use in OS2 - */ -#ifndef nsLocale_h__ -#define nsLocale_h__ - -#include "nsStringFwd.h" -#include "nsILocale.h" -#include "plhash.h" - -class nsLocale : public nsILocale { - friend class nsLocaleService; - NS_DECL_THREADSAFE_ISUPPORTS - -public: - nsLocale(void); - - /* Declare methods from nsILocale */ - NS_DECL_NSILOCALE - -protected: - - NS_IMETHOD AddCategory(const nsAString& category, const nsAString& value); - - static PLHashNumber Hash_HashFunction(const void* key); - static int Hash_CompareNSString(const void* s1, const void* s2); - static int Hash_EnumerateDelete(PLHashEntry *he, int hashIndex, void *arg); - - PLHashTable* fHashtable; - uint32_t fCategoryCount; - - virtual ~nsLocale(void); -}; - - -#endif
--- a/intl/locale/nsLocaleConstructors.h +++ b/intl/locale/nsLocaleConstructors.h @@ -4,17 +4,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef nsLocaleConstructors_h__ #define nsLocaleConstructors_h__ #include "nsCollation.h" #include "nsCollationCID.h" #include "mozilla/ModuleUtils.h" -#include "nsILocaleService.h" #include "nsIScriptableDateFormat.h" #include "nsIServiceManager.h" #include "nsPlatformCharset.h" #include "LocaleService.h" #include "OSPreferences.h" #define NSLOCALE_MAKE_CTOR(ctor_, iface_, func_) \ static nsresult \ @@ -28,17 +27,16 @@ ctor_(nsISupports* aOuter, REFNSIID aIID if (NS_SUCCEEDED(rv)) { \ rv = inst->QueryInterface(aIID, aResult); \ NS_RELEASE(inst); \ } \ return rv; \ } -NSLOCALE_MAKE_CTOR(CreateLocaleService, nsILocaleService, NS_NewLocaleService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollation) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCollationFactory) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPlatformCharset, Init) namespace mozilla { namespace intl { NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(LocaleService, LocaleService::GetInstanceAddRefed)
deleted file mode 100644 --- a/intl/locale/nsLocaleService.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nsCOMPtr.h" -#include "nsILocale.h" -#include "nsILocaleService.h" -#include "nsLocale.h" -#include "nsCRT.h" -#include "prprf.h" -#include "nsTArray.h" -#include "nsString.h" -#include "mozilla/UniquePtr.h" - -#include <ctype.h> - -#if defined(XP_WIN) -# include "nsWin32Locale.h" -#elif defined(XP_MACOSX) -# include <Carbon/Carbon.h> -#elif defined(XP_UNIX) -# include <locale.h> -# include <stdlib.h> -# include "nsPosixLocale.h" -#endif - -using namespace mozilla; - -// -// implementation constants -const int LocaleListLength = 6; -const char* LocaleList[LocaleListLength] = -{ - NSILOCALE_COLLATE, - NSILOCALE_CTYPE, - NSILOCALE_MONETARY, - NSILOCALE_NUMERIC, - NSILOCALE_TIME, - NSILOCALE_MESSAGE -}; - -#define NSILOCALE_MAX_ACCEPT_LANGUAGE 16 -#define NSILOCALE_MAX_ACCEPT_LENGTH 18 - -#if (defined(XP_UNIX) && !defined(XP_MACOSX)) -static int posix_locale_category[LocaleListLength] = -{ - LC_COLLATE, - LC_CTYPE, - LC_MONETARY, - LC_NUMERIC, - LC_TIME, -#ifdef HAVE_I18N_LC_MESSAGES - LC_MESSAGES -#else - LC_CTYPE -#endif -}; -#endif - -// -// nsILocaleService implementation -// -class nsLocaleService: public nsILocaleService { - -public: - - // - // nsISupports - // - NS_DECL_THREADSAFE_ISUPPORTS - - // - // nsILocaleService - // - NS_DECL_NSILOCALESERVICE - - - nsLocaleService(void); - -protected: - - nsresult SetSystemLocale(void); - nsresult SetApplicationLocale(void); - - nsCOMPtr<nsILocale> mSystemLocale; - nsCOMPtr<nsILocale> mApplicationLocale; - - virtual ~nsLocaleService(void); -}; - -// -// nsLocaleService methods -// -nsLocaleService::nsLocaleService(void) -{ -#ifdef XP_WIN - nsAutoString xpLocale; - // - // get the system LCID - // - LCID win_lcid = GetSystemDefaultLCID(); - NS_ENSURE_TRUE_VOID(win_lcid); - nsWin32Locale::GetXPLocale(win_lcid, xpLocale); - nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale)); - NS_ENSURE_SUCCESS_VOID(rv); - - // - // get the application LCID - // - win_lcid = GetUserDefaultLCID(); - NS_ENSURE_TRUE_VOID(win_lcid); - nsWin32Locale::GetXPLocale(win_lcid, xpLocale); - rv = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale)); - NS_ENSURE_SUCCESS_VOID(rv); -#endif -#if defined(XP_UNIX) && !defined(XP_MACOSX) - RefPtr<nsLocale> resultLocale(new nsLocale()); - NS_ENSURE_TRUE_VOID(resultLocale); - - // Get system configuration - const char* lang = getenv("LANG"); - - nsAutoString xpLocale, platformLocale; - nsAutoString category, category_platform; - int i; - - for( i = 0; i < LocaleListLength; i++ ) { - nsresult result; - // setlocale( , "") evaluates LC_* and LANG - char* lc_temp = setlocale(posix_locale_category[i], ""); - CopyASCIItoUTF16(LocaleList[i], category); - category_platform = category; - category_platform.AppendLiteral("##PLATFORM"); - - bool lc_temp_valid = lc_temp != nullptr; - -#if defined(MOZ_WIDGET_ANDROID) - // Treat the "C" env as nothing useful. See Bug 1095298. - lc_temp_valid = lc_temp_valid && strcmp(lc_temp, "C") != 0; -#endif - - if (lc_temp_valid) { - result = nsPosixLocale::GetXPLocale(lc_temp, xpLocale); - CopyASCIItoUTF16(lc_temp, platformLocale); - } else { - if ( lang == nullptr ) { - platformLocale.AssignLiteral("en_US"); - result = nsPosixLocale::GetXPLocale("en-US", xpLocale); - } else { - CopyASCIItoUTF16(lang, platformLocale); - result = nsPosixLocale::GetXPLocale(lang, xpLocale); - } - } - if (NS_FAILED(result)) { - return; - } - resultLocale->AddCategory(category, xpLocale); - resultLocale->AddCategory(category_platform, platformLocale); - } - mSystemLocale = do_QueryInterface(resultLocale); - mApplicationLocale = do_QueryInterface(resultLocale); - -#endif // XP_UNIX - -#ifdef XP_MACOSX - // Get string representation of user's current locale - CFLocaleRef userLocaleRef = ::CFLocaleCopyCurrent(); - CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef); - ::CFRetain(userLocaleStr); - - AutoTArray<UniChar, 32> buffer; - int size = ::CFStringGetLength(userLocaleStr); - buffer.SetLength(size + 1); - CFRange range = ::CFRangeMake(0, size); - ::CFStringGetCharacters(userLocaleStr, range, buffer.Elements()); - buffer[size] = 0; - - // Convert the locale string to the format that Mozilla expects - nsAutoString xpLocale(reinterpret_cast<char16_t*>(buffer.Elements())); - xpLocale.ReplaceChar('_', '-'); - - nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale)); - if (NS_SUCCEEDED(rv)) { - mApplicationLocale = mSystemLocale; - } - - ::CFRelease(userLocaleStr); - ::CFRelease(userLocaleRef); - - NS_ASSERTION(mApplicationLocale, "Failed to create locale objects"); -#endif // XP_MACOSX -} - -nsLocaleService::~nsLocaleService(void) -{ -} - -NS_IMPL_ISUPPORTS(nsLocaleService, nsILocaleService) - -NS_IMETHODIMP -nsLocaleService::NewLocale(const nsAString &aLocale, nsILocale **_retval) -{ - nsresult result; - - *_retval = nullptr; - - RefPtr<nsLocale> resultLocale(new nsLocale()); - if (!resultLocale) return NS_ERROR_OUT_OF_MEMORY; - - for (int32_t i = 0; i < LocaleListLength; i++) { - NS_ConvertASCIItoUTF16 category(LocaleList[i]); - result = resultLocale->AddCategory(category, aLocale); - if (NS_FAILED(result)) return result; -#if defined(XP_UNIX) && !defined(XP_MACOSX) - category.AppendLiteral("##PLATFORM"); - result = resultLocale->AddCategory(category, aLocale); - if (NS_FAILED(result)) return result; -#endif - } - - NS_ADDREF(*_retval = resultLocale); - return NS_OK; -} - - -NS_IMETHODIMP -nsLocaleService::GetSystemLocale(nsILocale **_retval) -{ - if (mSystemLocale) { - NS_ADDREF(*_retval = mSystemLocale); - return NS_OK; - } - - *_retval = (nsILocale*)nullptr; - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsLocaleService::GetApplicationLocale(nsILocale **_retval) -{ - if (mApplicationLocale) { - NS_ADDREF(*_retval = mApplicationLocale); - return NS_OK; - } - - *_retval=(nsILocale*)nullptr; - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsLocaleService::GetLocaleFromAcceptLanguage(const char *acceptLanguage, nsILocale **_retval) -{ - char* cPtr; - char* cPtr1; - char* cPtr2; - int i; - int j; - int countLang = 0; - char acceptLanguageList[NSILOCALE_MAX_ACCEPT_LANGUAGE][NSILOCALE_MAX_ACCEPT_LENGTH]; - nsresult result; - - auto input = MakeUnique<char[]>(strlen(acceptLanguage)+1); - - strcpy(input.get(), acceptLanguage); - cPtr1 = input.get()-1; - cPtr2 = input.get(); - - /* put in standard form */ - while (*(++cPtr1)) { - if (isalpha(*cPtr1)) *cPtr2++ = tolower(*cPtr1); /* force lower case */ - else if (isspace(*cPtr1)) ; /* ignore any space */ - else if (*cPtr1=='-') *cPtr2++ = '_'; /* "-" -> "_" */ - else if (*cPtr1=='*') ; /* ignore "*" */ - else *cPtr2++ = *cPtr1; /* else unchanged */ - } - *cPtr2 = '\0'; - - countLang = 0; - - if (strchr(input.get(), ';')) { - /* deal with the quality values */ - - float qvalue[NSILOCALE_MAX_ACCEPT_LANGUAGE]; - float qSwap; - float bias = 0.0f; - char* ptrLanguage[NSILOCALE_MAX_ACCEPT_LANGUAGE]; - char* ptrSwap; - - cPtr = nsCRT::strtok(input.get(),",",&cPtr2); - while (cPtr) { - qvalue[countLang] = 1.0f; - /* add extra parens to get rid of warning */ - if ((cPtr1 = strchr(cPtr,';')) != nullptr) { - PR_sscanf(cPtr1,";q=%f",&qvalue[countLang]); - *cPtr1 = '\0'; - } - if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LANGUAGE) { /* ignore if too long */ - qvalue[countLang] -= (bias += 0.0001f); /* to insure original order */ - ptrLanguage[countLang++] = cPtr; - if (countLang>=NSILOCALE_MAX_ACCEPT_LANGUAGE) break; /* quit if too many */ - } - cPtr = nsCRT::strtok(cPtr2,",",&cPtr2); - } - - /* sort according to decending qvalue */ - /* not a very good algorithm, but count is not likely large */ - for ( i=0 ; i<countLang-1 ; i++ ) { - for ( j=i+1 ; j<countLang ; j++ ) { - if (qvalue[i]<qvalue[j]) { - qSwap = qvalue[i]; - qvalue[i] = qvalue[j]; - qvalue[j] = qSwap; - ptrSwap = ptrLanguage[i]; - ptrLanguage[i] = ptrLanguage[j]; - ptrLanguage[j] = ptrSwap; - } - } - } - for ( i=0 ; i<countLang ; i++ ) { - PL_strncpyz(acceptLanguageList[i],ptrLanguage[i],NSILOCALE_MAX_ACCEPT_LENGTH); - } - - } else { - /* simple case: no quality values */ - - cPtr = nsCRT::strtok(input.get(),",",&cPtr2); - while (cPtr) { - if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LENGTH) { /* ignore if too long */ - PL_strncpyz(acceptLanguageList[countLang++],cPtr,NSILOCALE_MAX_ACCEPT_LENGTH); - if (countLang>=NSILOCALE_MAX_ACCEPT_LENGTH) break; /* quit if too many */ - } - cPtr = nsCRT::strtok(cPtr2,",",&cPtr2); - } - } - - // - // now create the locale - // - result = NS_ERROR_FAILURE; - if (countLang>0) { - result = NewLocale(NS_ConvertASCIItoUTF16(acceptLanguageList[0]), _retval); - } - - // - // clean up - // - return result; -} - - -nsresult -nsLocaleService::GetLocaleComponentForUserAgent(nsAString& retval) -{ - nsCOMPtr<nsILocale> system_locale; - nsresult 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; -} - - - -nsresult -NS_NewLocaleService(nsILocaleService** result) -{ - if(!result) - return NS_ERROR_NULL_POINTER; - *result = new nsLocaleService(); - if (! *result) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*result); - return NS_OK; -}
deleted file mode 100644 --- a/intl/locale/nsPosixLocale.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsIPosixLocale_h__ -#define nsIPosixLocale_h__ - - -#include "nscore.h" -#include "nsString.h" - -#define MAX_LANGUAGE_CODE_LEN 3 -#define MAX_COUNTRY_CODE_LEN 3 -#define MAX_LOCALE_LEN 128 -#define MAX_EXTRA_LEN 65 - -class nsPosixLocale { - -public: - static nsresult GetPlatformLocale(const nsAString& locale, nsACString& posixLocale); - static nsresult GetXPLocale(const char* posixLocale, nsAString& locale); -}; - -#endif
--- a/intl/locale/nsScriptableDateFormat.cpp +++ b/intl/locale/nsScriptableDateFormat.cpp @@ -3,19 +3,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "DateTimeFormat.h" #include "mozilla/Sprintf.h" #include "nsIScriptableDateFormat.h" #include "nsCOMPtr.h" #include "nsServiceManagerUtils.h" -#include "nsILocaleService.h" - -static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID); class nsScriptableDateFormat final : public nsIScriptableDateFormat { public: NS_DECL_ISUPPORTS NS_IMETHOD FormatDateTime(const char16_t *locale, nsDateFormatSelector dateFormatSelector, nsTimeFormatSelector timeFormatSelector,
deleted file mode 100644 --- a/intl/locale/nsWin32Locale.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsWin32Locale_h__ -#define nsWin32Locale_h__ - -#include "nscore.h" -#include "nsString.h" -#include <windows.h> - - -class nsWin32Locale final { -public: - static nsresult GetPlatformLocale(const nsAString& locale, LCID* winLCID); - static void GetXPLocale(LCID winLCID, nsAString& locale); - -private: - // Static class - Don't allow instantiation. - nsWin32Locale(void) {} -}; - -#endif
deleted file mode 100644 --- a/intl/locale/tests/nsLocaleTest.html +++ /dev/null @@ -1,44 +0,0 @@ -<html> -<head> - <title>nsLocale Scriptability Test</title> - -</head> - -<script> - -var localeService = null; -var applicationLocale = null; -var systemLocale = null; - -function get_locale_service() { - localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"].createInstance(); - localeService = localeService.QueryInterface(Components.interfaces.nsILocaleService); - applicationLocale = localeService.GetApplicationLocale(); - systemLocale = localeService.GetSystemLocale(); -} - -function do_application_locale(t) { - t.value = applicationLocale.GetCategory("NSILOCALE_MESSAGES"); -} - -function do_system_locale(t) { - t.value = systemLocale.GetCategory("NSILOCALE_MESSAGES"); -} - -</script> - -<body BGCOLOR="#FFFFFF" TEXT="#000000" onLoad="get_locale_service();"> - -<form name="locale"> -<b>Application Locale: </b> -<input type="button" value="Get Application Locale" onClick=do_application_locale(this);></br> -<b>System Locale: </b> -<input type="button" value="Get System Locale" onClick=do_system_locale(this);></br> -</form> - -<hr> -<address><a href="mailto:tague@netscape.com">Tague Griffith</a></address> -</body> -</html> - -
--- a/intl/locale/unix/moz.build +++ b/intl/locale/unix/moz.build @@ -1,18 +1,14 @@ # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- # vim: set filetype=python: # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -SOURCES += [ - 'nsPosixLocale.cpp', -] - if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android': SOURCES += [ 'nsUNIXCharset.cpp', ] GENERATED_FILES = [ 'unixcharset.properties.h', ] unixcharset = GENERATED_FILES['unixcharset.properties.h']
deleted file mode 100644 --- a/intl/locale/unix/nsPosixLocale.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "nscore.h" -#include "nsString.h" -#include "nsPosixLocale.h" -#include "mozilla/Sprintf.h" -#include "plstr.h" -#include "nsReadableUtils.h" - -static bool -ParseLocaleString(const char* locale_string, char* language, char* country, char* extra, char separator); - -nsresult -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_LossyConvertUTF16toASCII xp_locale(locale); - - 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 - return NS_OK; - } - - if (*country_code) { - if (*extra) { - SprintfLiteral(posix_locale,"%s_%s.%s",lang_code,country_code,extra); - } - else { - SprintfLiteral(posix_locale,"%s_%s",lang_code,country_code); - } - } - else { - if (*extra) { - SprintfLiteral(posix_locale,"%s.%s",lang_code,extra); - } - else { - SprintfLiteral(posix_locale,"%s",lang_code); - } - } - - posixLocale = posix_locale; - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -nsresult -nsPosixLocale::GetXPLocale(const char* posixLocale, nsAString& locale) -{ - 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]; - - if (posixLocale!=nullptr) { - if (strcmp(posixLocale,"C")==0 || strcmp(posixLocale,"POSIX")==0) { - locale.AssignLiteral("en-US"); - return NS_OK; - } - if (strcmp(posixLocale,"C.UTF-8")==0) { - locale.AssignLiteral("en-US.UTF-8"); - return NS_OK; - } - if (!ParseLocaleString(posixLocale,lang_code,country_code,extra,'_')) { -// * locale = "x-user-defined"; - // use posix if parse failed - CopyASCIItoUTF16(nsDependentCString(posixLocale), locale); - return NS_OK; - } - - // Special case: substitute "nb" (Norwegian Bokmal) for macrolanguage - // code "no" (Norwegian) - if (nsDependentCString(lang_code).LowerCaseEqualsLiteral("no")) { - lang_code[1] = 'b'; - } - - if (*country_code) { - SprintfLiteral(posix_locale,"%s-%s",lang_code,country_code); - } - else { - SprintfLiteral(posix_locale,"%s",lang_code); - } - - CopyASCIItoUTF16(nsDependentCString(posix_locale), locale); - return NS_OK; - - } - - return NS_ERROR_FAILURE; - -} - -// -// returns false/true depending on if it was of the form LL-CC.Extra -static bool -ParseLocaleString(const char* locale_string, char* language, char* country, char* extra, char separator) -{ - const char *src = locale_string; - char modifier[MAX_EXTRA_LEN+1]; - char *dest; - int dest_space, len; - - *language = '\0'; - *country = '\0'; - *extra = '\0'; - if (strlen(locale_string) < 2) { - return(false); - } - - // - // parse the language part - // - dest = language; - dest_space = MAX_LANGUAGE_CODE_LEN; - while ((*src) && (isalpha(*src)) && (dest_space--)) { - *dest++ = tolower(*src++); - } - *dest = '\0'; - len = dest - language; - if ((len != 2) && (len != 3)) { - NS_ASSERTION((len == 2) || (len == 3), "language code too short"); - NS_ASSERTION(len < 3, "reminder: verify we can handle 3+ character language code in all parts of the system; eg: language packs"); - *language = '\0'; - return(false); - } - - // check if all done - if (*src == '\0') { - return(true); - } - - if ((*src != '_') && (*src != '-') && (*src != '.') && (*src != '@')) { - NS_ASSERTION(isalpha(*src), "language code too long"); - NS_ASSERTION(!isalpha(*src), "unexpected language/country separator"); - *language = '\0'; - return(false); - } - - // - // parse the country part - // - if ((*src == '_') || (*src == '-')) { - src++; - dest = country; - dest_space = MAX_COUNTRY_CODE_LEN; - while ((*src) && (isalpha(*src)) && (dest_space--)) { - *dest++ = toupper(*src++); - } - *dest = '\0'; - len = dest - country; - if (len != 2) { - NS_ASSERTION(len == 2, "unexpected country code length"); - *language = '\0'; - *country = '\0'; - return(false); - } - } - - // check if all done - if (*src == '\0') { - return(true); - } - - if ((*src != '.') && (*src != '@')) { - NS_ASSERTION(isalpha(*src), "country code too long"); - NS_ASSERTION(!isalpha(*src), "unexpected country/extra separator"); - *language = '\0'; - *country = '\0'; - return(false); - } - - // - // handle the extra part - // - if (*src == '.') { - src++; // move past the extra part separator - dest = extra; - dest_space = MAX_EXTRA_LEN; - while ((*src) && (*src != '@') && (dest_space--)) { - *dest++ = *src++; - } - *dest = '\0'; - len = dest - extra; - if (len < 1) { - NS_ASSERTION(len > 0, "found country/extra separator but no extra code"); - *language = '\0'; - *country = '\0'; - *extra = '\0'; - return(false); - } - } - - // check if all done - if (*src == '\0') { - return(true); - } - - // - // handle the modifier part - // - - if (*src == '@') { - src++; // move past the modifier separator - NS_ASSERTION(strcmp("euro",src) == 0, "found non euro modifier"); - dest = modifier; - dest_space = MAX_EXTRA_LEN; - while ((*src) && (dest_space--)) { - *dest++ = *src++; - } - *dest = '\0'; - len = dest - modifier; - if (len < 1) { - NS_ASSERTION(len > 0, "found modifier separator but no modifier code"); - *language = '\0'; - *country = '\0'; - *extra = '\0'; - *modifier = '\0'; - return(false); - } - } - - // check if all done - if (*src == '\0') { - return(true); - } - - NS_ASSERTION(*src == '\0', "extra/modifier code too long"); - *language = '\0'; - *country = '\0'; - *extra = '\0'; - - return(false); -} -
--- a/intl/locale/windows/moz.build +++ b/intl/locale/windows/moz.build @@ -1,16 +1,15 @@ # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- # vim: set filetype=python: # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. SOURCES += [ - 'nsWin32Locale.cpp', 'nsWinCharset.cpp', ] if CONFIG['ENABLE_INTL_API']: SOURCES += ['OSPreferences_win.cpp'] FINAL_LIBRARY = 'xul'
deleted file mode 100644 --- a/intl/locale/windows/nsWin32Locale.cpp +++ /dev/null @@ -1,620 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "mozilla/ArrayUtils.h" - -#include "nscore.h" -#include "nsString.h" -#include "nsReadableUtils.h" -#include "nsWin32Locale.h" -#include <windows.h> - -using namespace mozilla; - -struct iso_pair -{ - const char* iso_code; - DWORD win_code; -}; - -struct iso_map -{ - const char* iso_code; - DWORD win_code; - iso_pair sublang_list[20]; -}; - -// -// This list is used to map between ISO language -// References : -// http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html -// http://www.loc.gov/standards/iso639-2/ -// http://www.ethnologue.com/ -// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_19ir.asp -// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/nls_61df.asp - -static const -iso_map iso_list[] = -{ - {"af", LANG_AFRIKAANS, { - { "ZA", SUBLANG_DEFAULT }, - { "",0}} - }, - { "ar", LANG_ARABIC, { - { "SA", SUBLANG_ARABIC_SAUDI_ARABIA }, - { "IQ", SUBLANG_ARABIC_IRAQ }, - { "EG", SUBLANG_ARABIC_EGYPT }, - { "LY", SUBLANG_ARABIC_LIBYA }, - { "DZ", SUBLANG_ARABIC_ALGERIA }, - { "MA", SUBLANG_ARABIC_MOROCCO }, - { "TN", SUBLANG_ARABIC_TUNISIA }, - { "OM", SUBLANG_ARABIC_OMAN }, - { "YE", SUBLANG_ARABIC_YEMEN }, - { "SY", SUBLANG_ARABIC_SYRIA }, - { "JO", SUBLANG_ARABIC_JORDAN }, - { "LB", SUBLANG_ARABIC_LEBANON }, - { "KW", SUBLANG_ARABIC_KUWAIT }, - { "AE", SUBLANG_ARABIC_UAE }, - { "BH", SUBLANG_ARABIC_BAHRAIN }, - { "QA", SUBLANG_ARABIC_QATAR }, - {"",0}} - }, - {"az", LANG_AZERI, { - { "AZ",SUBLANG_DEFAULT }, // XXX Latin vs Cyrillic vs Arabic - { "",0}} - }, - {"be", LANG_BELARUSIAN, { - { "BY",SUBLANG_DEFAULT }, - { "",0}} - }, - {"bg", LANG_BULGARIAN, { - { "BG", SUBLANG_DEFAULT }, - { "",0}} - }, - {"ca", LANG_CATALAN, { - { "ES", SUBLANG_DEFAULT}, - { "",0}} - }, - {"cs", LANG_CZECH, { - { "CZ", SUBLANG_DEFAULT}, - {"",0}} - }, - { "da", LANG_DANISH, { - { "DK", SUBLANG_DEFAULT }, - { "",0}} - }, - { "de", LANG_GERMAN, { - { "DE", SUBLANG_GERMAN }, - { "CH", SUBLANG_GERMAN_SWISS }, - { "AT", SUBLANG_GERMAN_AUSTRIAN }, - { "LU", SUBLANG_GERMAN_LUXEMBOURG }, - { "LI", SUBLANG_GERMAN_LIECHTENSTEIN }, - { "" , 0}} - }, - {"dv", LANG_DIVEHI, { - { "MV", SUBLANG_DEFAULT}, - { "", 0}} - }, - {"el", LANG_GREEK, { - { "GR", SUBLANG_DEFAULT}, - { "", 0}} - }, - { "en", LANG_ENGLISH, { - { "US", SUBLANG_ENGLISH_US }, - { "GB", SUBLANG_ENGLISH_UK }, - { "AU", SUBLANG_ENGLISH_AUS }, - { "CA", SUBLANG_ENGLISH_CAN }, - { "NZ", SUBLANG_ENGLISH_NZ }, - { "IE", SUBLANG_ENGLISH_EIRE }, - { "ZA", SUBLANG_ENGLISH_SOUTH_AFRICA }, - { "JM", SUBLANG_ENGLISH_JAMAICA }, - { "BZ", SUBLANG_ENGLISH_BELIZE }, - { "TT", SUBLANG_ENGLISH_TRINIDAD }, - { "ZW", SUBLANG_ENGLISH_ZIMBABWE }, - { "PH", SUBLANG_ENGLISH_PHILIPPINES }, - { "",0}} - }, - { "es", LANG_SPANISH, { // XXX : SUBLANG_SPANISH_MODERN - { "ES", SUBLANG_SPANISH }, - { "MX", SUBLANG_SPANISH_MEXICAN }, - { "GT", SUBLANG_SPANISH_GUATEMALA }, - { "CR", SUBLANG_SPANISH_COSTA_RICA }, - { "PA", SUBLANG_SPANISH_PANAMA }, - { "DO", SUBLANG_SPANISH_DOMINICAN_REPUBLIC }, - { "VE", SUBLANG_SPANISH_VENEZUELA }, - { "CO", SUBLANG_SPANISH_COLOMBIA }, - { "PE", SUBLANG_SPANISH_PERU }, - { "AR", SUBLANG_SPANISH_ARGENTINA }, - { "EC", SUBLANG_SPANISH_ECUADOR }, - { "CL", SUBLANG_SPANISH_CHILE }, - { "UY", SUBLANG_SPANISH_URUGUAY }, - { "PY", SUBLANG_SPANISH_PARAGUAY }, - { "BO", SUBLANG_SPANISH_BOLIVIA }, - { "SV", SUBLANG_SPANISH_EL_SALVADOR }, - { "HN", SUBLANG_SPANISH_HONDURAS }, - { "NI", SUBLANG_SPANISH_NICARAGUA }, - { "PR", SUBLANG_SPANISH_PUERTO_RICO }, - { "", 0 }} - }, - {"et", LANG_ESTONIAN, { - { "EE", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"eu", LANG_BASQUE, { - { "ES" , SUBLANG_DEFAULT }, - { "" , 0 }} - }, - {"fa", LANG_FARSI, { - { "IR", SUBLANG_DEFAULT}, - { "", 0}} - }, - {"fi", LANG_FINNISH, { - { "FI", SUBLANG_DEFAULT }, - { "",0}} - }, - {"fo", LANG_FAEROESE, { - { "FO", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "fr", LANG_FRENCH, { - { "FR", SUBLANG_FRENCH }, - { "BE", SUBLANG_FRENCH_BELGIAN }, - { "CA", SUBLANG_FRENCH_CANADIAN }, - { "CH", SUBLANG_FRENCH_SWISS }, - { "LU", SUBLANG_FRENCH_LUXEMBOURG }, - { "MC", SUBLANG_FRENCH_MONACO }, - {"",0}} - }, - { "gl", LANG_GALICIAN, { - { "ES", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "gu", LANG_GUJARATI, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"he", LANG_HEBREW, { - { "IL", SUBLANG_DEFAULT}, - { "", 0}} - }, - {"hi", LANG_HINDI, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - /* Duplicate the SUBLANG codes for Croatian and Serbian, because the Windows - LANG code is the same for both */ - {"hr", LANG_CROATIAN, { - { "CS", SUBLANG_SERBIAN_LATIN }, - { "SP", SUBLANG_SERBIAN_CYRILLIC }, - { "HR", SUBLANG_DEFAULT}, - { "" ,0 }} - }, - {"hu", LANG_HUNGARIAN, { - { "HU", SUBLANG_DEFAULT }, - { "" , 0 }} - }, - {"hy", LANG_ARMENIAN, { - { "AM", SUBLANG_DEFAULT}, - { "" ,0 }} - }, - {"id", LANG_INDONESIAN, { - { "ID", SUBLANG_DEFAULT }, - {"", 0}} - }, - {"is", LANG_ICELANDIC, { - { "IS", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "it", LANG_ITALIAN, { - { "IT", SUBLANG_ITALIAN }, - { "CH", SUBLANG_ITALIAN_SWISS }, - { "", 0}} - }, - {"iw", LANG_HEBREW, { - { "IL", SUBLANG_DEFAULT}, - { "", 0}} - }, - {"ja", LANG_JAPANESE, { - { "JP", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "ka", LANG_GEORGIAN, { - { "GE", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "kk", LANG_KAZAK, { - { "KZ", SUBLANG_DEFAULT }, // KAZAKHSTAN - { "", 0}} - }, - { "kn", LANG_KANNADA, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "ko", LANG_KOREAN, { - { "KR", SUBLANG_KOREAN }, - { "", 0}} - }, - { "kok", LANG_KONKANI, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "ky", LANG_KYRGYZ, { - { "KG", SUBLANG_DEFAULT }, // Kygyzstan - { "", 0}} - }, - {"lt", LANG_LITHUANIAN, { - { "LT", SUBLANG_DEFAULT }, - { "" ,0 }} - }, - {"lv", LANG_LATVIAN, { - { "LV", SUBLANG_DEFAULT}, - { "", 0}} - }, - {"mk", LANG_MACEDONIAN, { - { "MK", SUBLANG_DEFAULT }, - { "", 0 }} - }, - { "mn", LANG_MONGOLIAN, { - { "MN", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "mr", LANG_MARATHI, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"ms", LANG_MALAY, { - { "MY", SUBLANG_MALAY_MALAYSIA }, - { "BN", SUBLANG_MALAY_BRUNEI_DARUSSALAM }, // XXX - { "", 0}} - }, - {"nb", LANG_NORWEGIAN, { - { "NO", SUBLANG_NORWEGIAN_BOKMAL }, - { "", SUBLANG_NORWEGIAN_BOKMAL}} - }, - {"nl", LANG_DUTCH, { - {"NL", SUBLANG_DUTCH }, - {"BE", SUBLANG_DUTCH_BELGIAN }, - { "", 0}} - }, - {"nn", LANG_NORWEGIAN, { - { "NO", SUBLANG_NORWEGIAN_NYNORSK }, - { "", SUBLANG_NORWEGIAN_NYNORSK}} - }, - {"no", LANG_NORWEGIAN, { - { "NO", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "pa", LANG_PUNJABI, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"pl", LANG_POLISH, { - { "PL", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "pt", LANG_PORTUGUESE, { - { "PT", SUBLANG_PORTUGUESE }, - { "BR", SUBLANG_PORTUGUESE_BRAZILIAN }, - {"",0}} - }, - {"ro", LANG_ROMANIAN, { - { "RO", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"ru", LANG_RUSSIAN, { - { "RU", SUBLANG_DEFAULT }, - { "", 0 }} - }, - { "sa", LANG_SANSKRIT, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"sk", LANG_SLOVAK, { - { "SK", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"sl", LANG_SLOVENIAN, { - { "SI", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"sq", LANG_ALBANIAN, { - { "AL", SUBLANG_DEFAULT }, - { "", 0}} - }, - /* Duplicate the SUBLANG codes for Croatian and Serbian, because the Windows - LANG code is the same for both */ - {"sr", LANG_SERBIAN, { - { "CS", SUBLANG_SERBIAN_LATIN }, - { "SP", SUBLANG_SERBIAN_CYRILLIC }, - { "HR", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "sv", LANG_SWEDISH, { - { "SE", SUBLANG_SWEDISH }, - { "FI", SUBLANG_SWEDISH_FINLAND }, - { "", 0 }} - }, - {"sw", LANG_SWAHILI, { - { "KE", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "ta", LANG_TAMIL, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "te", LANG_TELUGU, { - { "IN", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"th", LANG_THAI, { - {"TH", SUBLANG_DEFAULT}, - {"",0}} - }, - {"tr", LANG_TURKISH, { - { "TR", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "tt", LANG_TATAR, { - { "RU", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"uk", LANG_UKRAINIAN, { - { "UA", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"ur", LANG_URDU, { - { "PK", SUBLANG_URDU_PAKISTAN }, - { "IN", SUBLANG_URDU_INDIA }, - { "", 0}} - }, - {"uz", LANG_UZBEK, { // XXX : Cyrillic, Latin - { "UZ", SUBLANG_DEFAULT }, - { "", 0}} - }, - {"vi", LANG_VIETNAMESE, { - { "VN", SUBLANG_DEFAULT }, - { "", 0}} - }, - { "zh", LANG_CHINESE, { - { "TW", SUBLANG_CHINESE_TRADITIONAL }, - { "CN", SUBLANG_CHINESE_SIMPLIFIED }, - { "HK", SUBLANG_CHINESE_HONGKONG }, - { "SG", SUBLANG_CHINESE_SINGAPORE }, - { "MO", SUBLANG_CHINESE_MACAU }, - { "",0}} - } -}; - -#define LENGTH_MAPPING_LIST ArrayLength(iso_list) - -// -// This list maps ISO 2 digit country codes to Win32 country codes. -// This list must be kept in alphabetic (by iso code) order and synchronized -// with the list above. This is only used in debug builds to check the consistentcy -// of the internal tables. -// -#ifdef DEBUG -static const -iso_pair dbg_list[] = -{ - {"af", LANG_AFRIKAANS}, - {"ar", LANG_ARABIC}, - {"az", LANG_AZERI}, - {"be", LANG_BELARUSIAN}, - {"bg", LANG_BULGARIAN}, - {"ca", LANG_CATALAN}, - {"cs", LANG_CZECH}, - {"da", LANG_DANISH}, - {"de", LANG_GERMAN}, - {"dv", LANG_DIVEHI}, - {"el", LANG_GREEK}, - {"en", LANG_ENGLISH}, - {"es", LANG_SPANISH}, - {"et", LANG_ESTONIAN}, - {"eu", LANG_BASQUE}, - {"fa", LANG_FARSI}, - {"fi", LANG_FINNISH}, - {"fo", LANG_FAEROESE}, - {"fr", LANG_FRENCH}, - {"gl", LANG_GALICIAN}, - {"gu", LANG_GUJARATI}, - {"he", LANG_HEBREW}, - {"hi", LANG_HINDI}, - {"hr", LANG_CROATIAN}, - {"hu", LANG_HUNGARIAN}, - {"hy", LANG_ARMENIAN}, - {"id", LANG_INDONESIAN}, - {"in", LANG_INDONESIAN}, - {"is", LANG_ICELANDIC}, - {"it", LANG_ITALIAN}, - {"iw", LANG_HEBREW}, - {"ja", LANG_JAPANESE}, - {"ka", LANG_GEORGIAN}, - {"kn", LANG_KANNADA}, - {"ko", LANG_KOREAN}, - {"kok", LANG_KONKANI}, - {"lt", LANG_LITHUANIAN}, - {"lv", LANG_LATVIAN}, - {"mk", LANG_MACEDONIAN}, - {"mn", LANG_MONGOLIAN}, - {"mr", LANG_MARATHI}, - {"ms", LANG_MALAY}, - {"nb", LANG_NORWEGIAN}, - {"nl", LANG_DUTCH}, - {"nn", LANG_NORWEGIAN}, - {"no", LANG_NORWEGIAN}, - {"pa", LANG_PUNJABI}, - {"pl", LANG_POLISH}, - {"pt", LANG_PORTUGUESE}, - {"ro", LANG_ROMANIAN}, - {"ru", LANG_RUSSIAN}, - {"sa", LANG_SANSKRIT}, - {"sk", LANG_SLOVAK}, - {"sl", LANG_SLOVENIAN}, - {"sq", LANG_ALBANIAN}, - {"sr", LANG_SERBIAN}, - {"sv", LANG_SWEDISH}, - {"sw", LANG_SWAHILI}, - {"ta", LANG_TAMIL}, - {"te", LANG_TELUGU}, - {"th", LANG_THAI}, - {"tr", LANG_TURKISH}, - {"tt", LANG_TATAR}, - {"uk", LANG_UKRAINIAN}, - {"ur", LANG_URDU}, - {"uz", LANG_UZBEK}, - {"vi", LANG_VIETNAMESE}, - {"zh", LANG_CHINESE}, - {"",0} -}; -#endif - -#define CROATIAN_ISO_CODE "hr" -#define SERBIAN_ISO_CODE "sr" - -// -// the mapping routines are a first approximation to get us going on -// the tier-1 languages. we are making an assumption that we can map -// language and country codes separately on Windows, which isn't true -// -nsresult -nsWin32Locale::GetPlatformLocale(const nsAString& locale, LCID* winLCID) -{ - LCID lcid = LocaleNameToLCID(PromiseFlatString(locale).get(), 0); - // The function returning 0 means that the locale name couldn't be matched, - // so we fallback to the old function - if (lcid != 0) { - *winLCID = lcid; - return NS_OK; - } - - char locale_string[9] = {'\0','\0','\0','\0','\0','\0','\0','\0','\0'}; - char* language_code; - char* country_code; - size_t i, j; - - // parse the locale - const char16_t* data = locale.BeginReading(); - j = locale.Length(); - for (i = 0; i < 7 && i < j; i++) { - locale_string[i] = data[i] == '-' ? '\0' : data[i]; - } - - language_code = locale_string; - country_code = locale_string + strlen(locale_string) + 1; - - // convert parsed locale to Windows LCID - for(i=0;i<LENGTH_MAPPING_LIST;i++) { - if (strcmp(language_code,iso_list[i].iso_code)==0) { - 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; - } - } - // here we have a language match but no country match - *winLCID = MAKELCID(MAKELANGID(iso_list[i].win_code,SUBLANG_DEFAULT),SORT_DEFAULT); - return NS_OK; - } - } - - return NS_ERROR_FAILURE; -} - -void -nsWin32Locale::GetXPLocale(LCID winLCID, nsAString& locale) -{ - locale.SetCapacity(LOCALE_NAME_MAX_LENGTH); - int length = LCIDToLocaleName(winLCID, - reinterpret_cast<LPWSTR>(locale.BeginWriting()), - LOCALE_NAME_MAX_LENGTH, 0); - // 0 length means that the function failed to match up the LCID, - // so we fallback to the old function - if (length) { - // length contains null terminate. - locale.SetLength(length - 1); - return; - } - - DWORD lang_id, sublang_id; - size_t i, j; - - lang_id = PRIMARYLANGID(LANGIDFROMLCID(winLCID)); - sublang_id = SUBLANGID(LANGIDFROMLCID(winLCID)); - - /* Special-case Norwegian Bokmal and Norwegian Nynorsk, which have the same - LANG_ID on Windows, but have separate ISO-639-2 codes */ - if (lang_id == LANG_NORWEGIAN) { - if (sublang_id == SUBLANG_NORWEGIAN_BOKMAL) { - locale.AssignASCII("nb-NO"); - } else if (sublang_id == SUBLANG_NORWEGIAN_NYNORSK) { - locale.AssignASCII("nn-NO"); - } else { - locale.AssignASCII("no-NO"); - } - return; - } - - for(i=0;i<LENGTH_MAPPING_LIST;i++) { - if (lang_id==iso_list[i].win_code) { - /* Special-case Croatian and Serbian, which have the same LANG_ID on - Windows, but have been split into separate ISO-639-2 codes */ - if (lang_id == LANG_CROATIAN) { - if (sublang_id == SUBLANG_DEFAULT) { - locale.AssignLiteral(CROATIAN_ISO_CODE); - } else { - locale.AssignLiteral(SERBIAN_ISO_CODE); - } - } else { - locale.AssignASCII(iso_list[i].iso_code); - } - for(j=0;iso_list[i].sublang_list[j].win_code;j++) { - if (sublang_id == iso_list[i].sublang_list[j].win_code) { - locale.Append(char16_t('-')); - locale.AppendASCII(iso_list[i].sublang_list[j].iso_code); - break; - } - } - return; - } - } - - // - // didn't find any match. fall back to en-US, which is better - // than unusable buttons without 'OK', 'Cancel', etc (bug 224546) - // - locale.AssignLiteral("en-US"); - return; -} - -#ifdef DEBUG -void -test_internal_tables(void) -{ - size_t i; - - for(i=1;i<LENGTH_MAPPING_LIST;i++) { - if (strcmp(dbg_list[i-1].iso_code,dbg_list[i].iso_code)>=0) - fprintf(stderr,"nsLocale: language_list %s and %s are not ordered\n",dbg_list[i-1].iso_code,dbg_list[i].iso_code); - } - - i=0; - while(strlen(dbg_list[i].iso_code)!=0) { - i++; - } - if (i!=LENGTH_MAPPING_LIST) - fprintf(stderr,"nsLocale: language_list length is %u, reported length is %u\n", - unsigned(i), unsigned(LENGTH_MAPPING_LIST)); - - for(i=0;i<LENGTH_MAPPING_LIST;i++) { - if (strcmp(iso_list[i].iso_code,dbg_list[i].iso_code)!=0) { - fprintf(stderr,"nsLocale: iso_list and dbg_list different at item: %u\n", - unsigned(i)); - } - } -} - -#endif -
--- a/intl/locale/windows/nsWinCharset.cpp +++ b/intl/locale/windows/nsWinCharset.cpp @@ -3,17 +3,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/ArrayUtils.h" #include "nsIPlatformCharset.h" #include "nsUConvPropertySearch.h" #include <windows.h> -#include "nsWin32Locale.h" #include "nsString.h" #include "nsPlatformCharset.h" using namespace mozilla; static constexpr nsUConvProp kWinCharsets[] = { #include "wincharset.properties.h" };