From 4ce19437ce3ba752ea76ca70cefa175d1f511642 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 2 Sep 2022 11:03:31 +0000 Subject: [PATCH] Bug 1785216 - Migrate notification.dtd to Fluent. r=jaws,fluent-reviewers,flod,mconley Except for the close-notification-message, all of the notification.dtd strings are only used by popupnotification.js. Accordingly, the strings are migrated to two different FTL files. Differential Revision: https://phabricator.services.mozilla.com/D154890 --- .../static/browser_all_files_referenced.js | 4 ++ .../content/translation-notification.js | 8 ++-- .../bug_1785216_popupnotification.py | 44 +++++++++++++++++++ toolkit/content/customElements.js | 5 --- toolkit/content/widgets/notificationbox.js | 7 +-- toolkit/content/widgets/popupnotification.js | 29 ++++++++---- .../en-US/chrome/global/notification.dtd | 4 ++ .../en-US/toolkit/global/notification.ftl | 3 ++ .../toolkit/global/popupnotification.ftl | 10 +++++ 9 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 python/l10n/fluent_migrations/bug_1785216_popupnotification.py create mode 100644 toolkit/locales/en-US/toolkit/global/popupnotification.ftl diff --git a/browser/base/content/test/static/browser_all_files_referenced.js b/browser/base/content/test/static/browser_all_files_referenced.js index c757c713b261..f85d9f07b42b 100644 --- a/browser/base/content/test/static/browser_all_files_referenced.js +++ b/browser/base/content/test/static/browser_all_files_referenced.js @@ -284,6 +284,10 @@ var whitelist = [ // References to esm generated from jsm programatically { file: "resource://gre/modules/LangPackMatcher.sys.mjs" }, { file: "resource://gre/modules/PluralForm.sys.mjs" }, + + // Bug 1788595 - used by Firefox Translations extension + // see also https://github.com/mozilla/firefox-translations/issues/496 + { file: "chrome://global/locale/notification.dtd" }, ]; if (AppConstants.NIGHTLY_BUILD && AppConstants.platform != "win") { diff --git a/browser/components/translation/content/translation-notification.js b/browser/components/translation/content/translation-notification.js index 5f9f09172ac1..f7b02f36149e 100644 --- a/browser/components/translation/content/translation-notification.js +++ b/browser/components/translation/content/translation-notification.js @@ -77,19 +77,17 @@ class MozTranslationNotification extends MozElements.Notification { `; } static get entities() { - return [ - "chrome://global/locale/notification.dtd", - "chrome://browser/locale/translation.dtd", - ]; + return ["chrome://browser/locale/translation.dtd"]; } connectedCallback() { + MozXULElement.insertFTLIfNeeded("toolkit/global/notification.ftl"); this.appendChild(this.constructor.fragment); for (let [propertyName, selector] of [ diff --git a/python/l10n/fluent_migrations/bug_1785216_popupnotification.py b/python/l10n/fluent_migrations/bug_1785216_popupnotification.py new file mode 100644 index 000000000000..4f8478166043 --- /dev/null +++ b/python/l10n/fluent_migrations/bug_1785216_popupnotification.py @@ -0,0 +1,44 @@ +# coding=utf8 + +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +from __future__ import absolute_import +import fluent.syntax.ast as FTL +from fluent.migrate.helpers import transforms_from +from fluent.migrate.helpers import COPY + + +def migrate(ctx): + """Bug 1785216 - Migrate notification.dtd to Fluent, part {index}""" + + source = "toolkit/chrome/global/notification.dtd" + ctx.add_transforms( + "toolkit/toolkit/global/notification.ftl", + "toolkit/toolkit/global/notification.ftl", + transforms_from( + """ + +close-notification-message = + .tooltiptext = { COPY(path1, "closeNotification.tooltip") } +""", + path1=source, + ), + ) + + ctx.add_transforms( + "toolkit/toolkit/global/popupnotification.ftl", + "toolkit/toolkit/global/popupnotification.ftl", + transforms_from( + """ + +popup-notification-learn-more = { COPY(path1, "learnMoreNoEllipsis") } +popup-notification-more-actions-button = + .aria-label = { COPY(path1, "moreActionsButton.accessibleLabel") } +popup-notification-default-button = + .label = { COPY(path1, "defaultButton.label") } + .accesskey = { COPY(path1, "defaultButton.accesskey") } +""", + path1=source, + ), + ) diff --git a/toolkit/content/customElements.js b/toolkit/content/customElements.js index be18d0d86ea8..8bbe70369540 100644 --- a/toolkit/content/customElements.js +++ b/toolkit/content/customElements.js @@ -480,11 +480,6 @@ * return ` `; } - static get entities() { - return ["chrome://global/locale/notification.dtd"]; - } - constructor() { super(); this.persistence = 0; @@ -433,6 +429,7 @@ } connectedCallback() { + MozXULElement.insertFTLIfNeeded("toolkit/global/notification.ftl"); this.appendChild(this.constructor.fragment); for (let [propertyName, selector] of [ diff --git a/toolkit/content/widgets/popupnotification.js b/toolkit/content/widgets/popupnotification.js index 1c64f4e51139..21acadaff4f1 100644 --- a/toolkit/content/widgets/popupnotification.js +++ b/toolkit/content/widgets/popupnotification.js @@ -44,6 +44,13 @@ return; } + // If the label and/or accesskey for the primary button is set by + // inherited attributes, its data-l10n-id needs to be unset or + // DOM Localization will overwrite the values. + if (name === "buttonlabel" || name === "buttonaccesskey") { + document.l10n.setAttributes(this.button, ""); + } + super.attributeChangedCallback(name, oldValue, newValue); } @@ -78,10 +85,10 @@ - + - + @@ -90,27 +97,31 @@ -