From 5f63463ffac1172f81331fafbb608a61a8d8230a Mon Sep 17 00:00:00 2001 From: Pier Angelo Vendrame Date: Tue, 4 Jun 2024 18:54:45 +0000 Subject: [PATCH] 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 --- toolkit/actors/UAWidgetsChild.sys.mjs | 1 + toolkit/content/widgets/datetimebox.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/toolkit/actors/UAWidgetsChild.sys.mjs b/toolkit/actors/UAWidgetsChild.sys.mjs index 6f4244ffe9dd..947ec2492dc3 100644 --- a/toolkit/actors/UAWidgetsChild.sys.mjs +++ b/toolkit/actors/UAWidgetsChild.sys.mjs @@ -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"; diff --git a/toolkit/content/widgets/datetimebox.js b/toolkit/content/widgets/datetimebox.js index 1c63b09269a8..248c05a0c298 100644 --- a/toolkit/content/widgets/datetimebox.js +++ b/toolkit/content/widgets/datetimebox.js @@ -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 ); }