mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
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:
parent
b694d63ae3
commit
cc3d3ab8cd
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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*
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
@ -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>
|
@ -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
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user