Bug 1880108 - Pass the locale list when constructing l10n in datetimebox. r=reusable-components-reviewers,tgiles

The datetime input is inconsistent with other inputs when using spoof
English: its placeholder is not translated, unlike the default values
and texts of all the other inputs.

Differential Revision: https://phabricator.services.mozilla.com/D201726
This commit is contained in:
Pier Angelo Vendrame 2024-06-04 18:54:45 +00:00
parent e6b70d8c47
commit 5f63463ffa
2 changed files with 15 additions and 2 deletions

View file

@ -96,6 +96,7 @@ export class UAWidgetsChild extends JSWindowActorChild {
case "input":
uri = "chrome://global/content/elements/datetimebox.js";
widgetName = "DateTimeBoxWidget";
prefKeys = ["privacy.resistFingerprinting"];
break;
case "marquee":
uri = "chrome://global/content/elements/marquee.js";

View file

@ -12,17 +12,29 @@
* according to the value of the "type" property.
*/
this.DateTimeBoxWidget = class {
constructor(shadowRoot) {
constructor(shadowRoot, prefs) {
this.shadowRoot = shadowRoot;
this.element = shadowRoot.host;
this.document = this.element.ownerDocument;
this.window = this.document.defaultView;
// When undefined, DOMLocalization will use the app locales.
let locales;
if (prefs["privacy.resistFingerprinting"]) {
locales = [...this.window.getWebExposedLocales()];
// Make sure to always include en-US, in case the web exposed languages do
// not include a translation for the widget.
if (!locales.includes("en-US")) {
locales.push("en-US");
}
}
// The DOMLocalization instance needs to allow for sync methods so that
// the placeholder value may be determined and set during the
// createEditFieldAndAppend() call.
this.l10n = new this.window.DOMLocalization(
["toolkit/global/datetimebox.ftl"],
/* aSync = */ true
/* aSync = */ true,
undefined,
locales
);
}