Bug 1379905 - Switch mozIntl, datetimebox and DateTimeFormat to use GetRegionalPrefsLocales. r=jfkthame,smaug

MozReview-Commit-ID: IqGbT6ZUfuN

--HG--
rename : dom/tests/mochitest/chrome/test_window_getAppLocales.html => dom/tests/mochitest/chrome/test_window_getRegionalPrefsLocales.html
extra : rebase_source : 3180b337ec33bfc8959d0189c8a53ca2c3306e95
This commit is contained in:
Zibi Braniecki 2017-07-14 16:47:23 -07:00
parent b694d63ae3
commit cc3d3ab8cd
9 changed files with 28 additions and 33 deletions

View File

@ -15495,13 +15495,13 @@ nsGlobalWindow::GetPaintWorklet(ErrorResult& aRv)
}
void
nsGlobalWindow::GetAppLocalesAsBCP47(nsTArray<nsString>& aLocales)
nsGlobalWindow::GetRegionalPrefsLocales(nsTArray<nsString>& aLocales)
{
nsTArray<nsCString> appLocales;
mozilla::intl::LocaleService::GetInstance()->GetAppLocalesAsBCP47(appLocales);
AutoTArray<nsCString, 10> rpLocales;
mozilla::intl::LocaleService::GetInstance()->GetRegionalPrefsLocales(rpLocales);
for (uint32_t i = 0; i < appLocales.Length(); i++) {
aLocales.AppendElement(NS_ConvertUTF8toUTF16(appLocales[i]));
for (const auto& loc : rpLocales) {
aLocales.AppendElement(NS_ConvertUTF8toUTF16(loc));
}
}

View File

@ -969,7 +969,7 @@ public:
GetPaintWorklet(mozilla::ErrorResult& aRv);
void
GetAppLocalesAsBCP47(nsTArray<nsString>& aLocales);
GetRegionalPrefsLocales(nsTArray<nsString>& aLocales);
#ifdef ENABLE_INTL_API
mozilla::dom::IntlUtils*

View File

@ -91,4 +91,4 @@ 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]

View File

@ -20,7 +20,7 @@ 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 = [
{
@ -44,12 +44,12 @@ let testData = [
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,
}
},
];

View File

@ -14,9 +14,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1337234
<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>

View File

@ -519,7 +519,12 @@ partial interface Window {
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.
@ -529,7 +534,7 @@ partial interface Window {
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
*/
[Func="IsChromeOrXBL"]
sequence<DOMString> getAppLocalesAsBCP47();
sequence<DOMString> getRegionalPrefsLocales();
#ifdef ENABLE_INTL_API
/**

View File

@ -25,9 +25,9 @@ DateTimeFormat::Initialize()
}
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;
}

View File

@ -16,22 +16,12 @@ const osPrefs =
/**
* 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;
}

View File

@ -1202,7 +1202,7 @@
<![CDATA[
this.DEBUG = false;
this.mInputElement = this.parentNode;
this.mLocales = window.getAppLocalesAsBCP47();
this.mLocales = window.getRegionalPrefsLocales();
this.mIsRTL = false;
let intlUtils = window.intlUtils;