Bug 1379905 - Switch mozIntl, datetimebox and DateTimeFormat to use GetRegionalPrefsLocales. r=jfkthame
MozReview-Commit-ID: IqGbT6ZUfuN
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -15488,23 +15488,23 @@ nsGlobalWindow::GetPaintWorklet(ErrorRes
mPaintWorklet = new Worklet(AsInner(), principal, Worklet::ePaintWorklet);
}
return mPaintWorklet;
}
void
-nsGlobalWindow::GetAppLocalesAsBCP47(nsTArray<nsString>& aLocales)
-{
- nsTArray<nsCString> appLocales;
- mozilla::intl::LocaleService::GetInstance()->GetAppLocalesAsBCP47(appLocales);
-
- for (uint32_t i = 0; i < appLocales.Length(); i++) {
- aLocales.AppendElement(NS_ConvertUTF8toUTF16(appLocales[i]));
+nsGlobalWindow::GetRegionalPrefsLocales(nsTArray<nsString>& aLocales)
+{
+ AutoTArray<nsCString, 10> rpLocales;
+ mozilla::intl::LocaleService::GetInstance()->GetRegionalPrefsLocales(rpLocales);
+
+ for (const auto& loc : rpLocales) {
+ aLocales.AppendElement(NS_ConvertUTF8toUTF16(loc));
}
}
#ifdef ENABLE_INTL_API
IntlUtils*
nsGlobalWindow::GetIntlUtils(ErrorResult& aError)
{
MOZ_RELEASE_ASSERT(IsInnerWindow());
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -964,17 +964,17 @@ public:
mozilla::dom::Worklet*
GetAudioWorklet(mozilla::ErrorResult& aRv);
mozilla::dom::Worklet*
GetPaintWorklet(mozilla::ErrorResult& aRv);
void
- GetAppLocalesAsBCP47(nsTArray<nsString>& aLocales);
+ GetRegionalPrefsLocales(nsTArray<nsString>& aLocales);
#ifdef ENABLE_INTL_API
mozilla::dom::IntlUtils*
GetIntlUtils(mozilla::ErrorResult& aRv);
#endif
protected:
bool AlertOrConfirm(bool aAlert, const nsAString& aMessage,
--- a/dom/tests/mochitest/chrome/chrome.ini
+++ b/dom/tests/mochitest/chrome/chrome.ini
@@ -86,9 +86,9 @@ skip-if = os == 'linux'
[test_sandbox_postMessage.html]
[test_selectAtPoint.html]
[test_sizemode_attribute.xul]
tags = fullscreen
skip-if = os != 'win'
[test_subscript_bindings.xul]
[test_xray_event_constructor.xul]
[test_clipboard_events_chrome.html]
-[test_window_getAppLocales.html]
+[test_window_getRegionalPrefsLocales.html]
--- a/dom/tests/mochitest/chrome/test_intlUtils_getLocaleInfo.html
+++ b/dom/tests/mochitest/chrome/test_intlUtils_getLocaleInfo.html
@@ -15,17 +15,17 @@ https://bugzilla.mozilla.org/show_bug.cg
<script>
const Cc = Components.classes;
const Ci = Components.interfaces;
const localeService =
Cc["@mozilla.org/intl/localeservice;1"].getService(Ci.mozILocaleService);
const mozIntl = Cc["@mozilla.org/mozintl;1"].getService(Ci.mozIMozIntl);
-let appLocale = localeService.getAppLocalesAsBCP47()[0];
+let rpLocale = localeService.getRegionalPrefsLocales()[0];
let testData = [
{
locales: ["en-US"],
expected: {
locale: "en-US",
direction: "ltr",
}
@@ -39,22 +39,22 @@ let testData = [
},
{
locales: ["ar"],
expected: {
locale: "ar",
direction: "rtl",
}
},
- // IntlUtils uses current app locales if locales is not provided.
+ // IntlUtils uses current regional prefs locales if locales is not provided.
{
locales: [],
expected: {
- locale: appLocale,
- direction: mozIntl.getLocaleInfo(appLocale).direction,
+ locale: rpLocale,
+ direction: mozIntl.getLocaleInfo(rpLocale).direction,
}
},
];
let intlUtils = window.intlUtils;
ok(intlUtils, "window.intlUtils should exist");
for (let { locales, expected } of testData) {
rename from dom/tests/mochitest/chrome/test_window_getAppLocales.html
rename to dom/tests/mochitest/chrome/test_window_getRegionalPrefsLocales.html
--- a/dom/tests/mochitest/chrome/test_window_getAppLocales.html
+++ b/dom/tests/mochitest/chrome/test_window_getRegionalPrefsLocales.html
@@ -9,15 +9,15 @@ https://bugzilla.mozilla.org/show_bug.cg
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1337234">Mozilla Bug 1337234</a>
<p id="display"></p>
<div id="content" style="display: none">
<script>
-let appLocales = window.getAppLocalesAsBCP47();
-ok(appLocales.length > 0, "getAppLocales returns at least one locale.");
-is(appLocales[0], "en-US", "The first app locale should be en-US.");
+let rpLocales = window.getRegionalPrefsLocales();
+ok(rpLocales.length > 0, "getRegionalPrefsLocales returns at least one locale.");
+is(rpLocales[0], "en-US", "The first regional prefs locale should be en-US.");
</script>
</body>
</html>
--- a/dom/webidl/Window.webidl
+++ b/dom/webidl/Window.webidl
@@ -514,27 +514,32 @@ callback IdleRequestCallback = void (Idl
* particular do not use this to gate access to JavaScript APIs.
*/
partial interface Window {
[ChromeOnly] readonly attribute boolean isSecureContextIfOpenerIgnored;
};
partial interface Window {
/**
- * Returns a list of locales that the application should be localized to.
+ * Returns a list of locales that the internationalization components
+ * should be localized to.
+ *
+ * The function name refers to Regional Preferences which can be either
+ * fetched from the internal internationalization database (CLDR), or
+ * from the host environment.
*
* The result is a sorted list of valid locale IDs and it should be
* used for all APIs that accept list of locales, like ECMA402 and L10n APIs.
*
* This API always returns at least one locale.
*
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*/
[Func="IsChromeOrXBL"]
- sequence<DOMString> getAppLocalesAsBCP47();
+ sequence<DOMString> getRegionalPrefsLocales();
#ifdef ENABLE_INTL_API
/**
* Getter funcion for IntlUtils, which provides helper functions for
* localization.
*/
[Throws, Func="IsChromeOrXBL"]
readonly attribute IntlUtils intlUtils;
--- a/intl/locale/DateTimeFormat.cpp
+++ b/intl/locale/DateTimeFormat.cpp
@@ -20,19 +20,19 @@ nsCString* DateTimeFormat::mLocale = nul
/*static*/ nsresult
DateTimeFormat::Initialize()
{
if (mLocale) {
return NS_OK;
}
mLocale = new nsCString();
- nsAutoCString locale;
- intl::LocaleService::GetInstance()->GetAppLocaleAsBCP47(locale);
- mLocale->Assign(locale);
+ AutoTArray<nsCString, 10> regionalPrefsLocales;
+ intl::LocaleService::GetInstance()->GetRegionalPrefsLocales(regionalPrefsLocales);
+ mLocale->Assign(regionalPrefsLocales[0]);
return NS_OK;
}
// performs a locale sensitive date formatting operation on the time_t parameter
/*static*/ nsresult
DateTimeFormat::FormatTime(const nsDateFormatSelector aDateFormatSelector,
const nsTimeFormatSelector aTimeFormatSelector,
--- a/toolkit/components/mozintl/mozIntl.js
+++ b/toolkit/components/mozintl/mozIntl.js
@@ -11,32 +11,22 @@ const mozIntlHelper =
Cc["@mozilla.org/mozintlhelper;1"].getService(Ci.mozIMozIntlHelper);
const localeSvc =
Cc["@mozilla.org/intl/localeservice;1"].getService(Ci.mozILocaleService);
const osPrefs =
Cc["@mozilla.org/intl/ospreferences;1"].getService(Ci.mozIOSPreferences);
/**
* This helper function retrives currently used app locales, allowing
- * all mozIntl APIs to use the current app locales unless called with
- * explicitly listed locales.
+ * all mozIntl APIs to use the current regional prefs locales unless
+ * called with explicitly listed locales.
*/
function getLocales(locales) {
if (!locales) {
- return localeSvc.getAppLocalesAsBCP47();
- }
- return locales;
-}
-
-function getLocale(locales) {
- if (!locales) {
- return localeSvc.getAppLocale();
- }
- if (Array.isArray(locales)) {
- return [0];
+ return localeSvc.getRegionalPrefsLocales();
}
return locales;
}
function getDateTimePatternStyle(option) {
switch (option) {
case "full":
return osPrefs.dateTimeFormatStyleFull;
--- a/toolkit/content/widgets/datetimebox.xml
+++ b/toolkit/content/widgets/datetimebox.xml
@@ -1197,17 +1197,17 @@
</html:div>
</content>
<implementation implements="nsIDateTimeInputArea">
<constructor>
<![CDATA[
this.DEBUG = false;
this.mInputElement = this.parentNode;
- this.mLocales = window.getAppLocalesAsBCP47();
+ this.mLocales = window.getRegionalPrefsLocales();
this.mIsRTL = false;
let intlUtils = window.intlUtils;
if (intlUtils) {
this.mIsRTL =
intlUtils.getLocaleInfo(this.mLocales).direction === "rtl";
}