From 4470f15b3c11bed526a3762e45ca0f4e9d2dcdcf Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Tue, 23 May 2023 12:00:02 +0000 Subject: [PATCH] Bug 1793557 - Convert ExtensionsUI.jsm strings to Fluent. r=extension-reviewers,fluent-reviewers,flod,robwu Differential Revision: https://phabricator.services.mozilla.com/D178236 --- .../locales/en-US/browser/extensionsUI.ftl | 21 +++++++ .../en-US/chrome/browser/browser.properties | 17 ----- browser/modules/ExtensionsUI.jsm | 63 ++++++++++--------- .../bug_1793557_extensions.py | 62 ++++++++++++++++++ 4 files changed, 117 insertions(+), 46 deletions(-) create mode 100644 browser/locales/en-US/browser/extensionsUI.ftl diff --git a/browser/locales/en-US/browser/extensionsUI.ftl b/browser/locales/en-US/browser/extensionsUI.ftl new file mode 100644 index 000000000000..b21d6b96d374 --- /dev/null +++ b/browser/locales/en-US/browser/extensionsUI.ftl @@ -0,0 +1,21 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +webext-perms-learn-more = Learn more + +# Variables: +# $addonName (String): localized named of the extension that is asking to change the default search engine. +# $currentEngine (String): name of the current search engine. +# $newEngine (String): name of the new search engine. +webext-default-search-description = { $addonName } would like to change your default search engine from { $currentEngine } to { $newEngine }. Is that OK? +webext-default-search-yes = + .label = Yes + .accesskey = Y +webext-default-search-no = + .label = No + .accesskey = N + +# Variables: +# $addonName (String): localized named of the extension that was just installed. +addon-post-install-message = { $addonName } was added. diff --git a/browser/locales/en-US/chrome/browser/browser.properties b/browser/locales/en-US/chrome/browser/browser.properties index ab861d40b076..5355120fce47 100644 --- a/browser/locales/en-US/chrome/browser/browser.properties +++ b/browser/locales/en-US/chrome/browser/browser.properties @@ -27,23 +27,6 @@ contextMenuPrivateSearchOtherEngine.accesskey=h bookmarkAllTabsDefault=[Folder Name] -webextPerms.learnMore2=Learn more - -# LOCALIZATION NOTE (webext.defaultSearch.description) -# %1$S is replaced with the localized named of the extension that is asking to change the default search engine. -# %2$S is replaced with the name of the current search engine -# %3$S is replaced with the name of the new search engine -webext.defaultSearch.description=%1$S would like to change your default search engine from %2$S to %3$S. Is that OK? -webext.defaultSearchYes.label=Yes -webext.defaultSearchYes.accessKey=Y -webext.defaultSearchNo.label=No -webext.defaultSearchNo.accessKey=N - -# LOCALIZATION NOTE (addonPostInstall.message3) -# %S is replaced with the localized named of the extension that was -# just installed. -addonPostInstall.message3=%S was added. - unsignedAddonsDisabled.message=One or more installed add-ons cannot be verified and have been disabled. unsignedAddonsDisabled.learnMore.label=Learn More unsignedAddonsDisabled.learnMore.accesskey=L diff --git a/browser/modules/ExtensionsUI.jsm b/browser/modules/ExtensionsUI.jsm index 53648786577f..8ef74b4341bf 100644 --- a/browser/modules/ExtensionsUI.jsm +++ b/browser/modules/ExtensionsUI.jsm @@ -27,11 +27,15 @@ XPCOMUtils.defineLazyModuleGetters(lazy, { OriginControls: "resource://gre/modules/ExtensionPermissions.jsm", }); +XPCOMUtils.defineLazyGetter( + lazy, + "l10n", + () => new Localization(["browser/extensionsUI.ftl"], true) +); + const DEFAULT_EXTENSION_ICON = "chrome://mozapps/skin/extensions/extensionGeneric.svg"; -const BROWSER_PROPERTIES = "chrome://browser/locale/browser.properties"; - const HTML_NS = "http://www.w3.org/1999/xhtml"; function getTabBrowser(browser) { @@ -288,26 +292,30 @@ var ExtensionsUI = { let { browser, name, icon, respond, currentEngine, newEngine } = subject.wrappedJSObject; - let bundle = Services.strings.createBundle(BROWSER_PROPERTIES); + const [searchDesc, searchYes, searchNo] = lazy.l10n.formatMessagesSync([ + { + id: "webext-default-search-description", + args: { addonName: "<>", currentEngine, newEngine }, + }, + "webext-default-search-yes", + "webext-default-search-no", + ]); - let strings = {}; - strings.acceptText = bundle.GetStringFromName( - "webext.defaultSearchYes.label" - ); - strings.acceptKey = bundle.GetStringFromName( - "webext.defaultSearchYes.accessKey" - ); - strings.cancelText = bundle.GetStringFromName( - "webext.defaultSearchNo.label" - ); - strings.cancelKey = bundle.GetStringFromName( - "webext.defaultSearchNo.accessKey" - ); - strings.addonName = name; - strings.text = bundle.formatStringFromName( - "webext.defaultSearch.description", - ["<>", currentEngine, newEngine] - ); + const strings = { addonName: name, text: searchDesc.value }; + for (let attr of searchYes.attributes) { + if (attr.name === "label") { + strings.acceptText = attr.value; + } else if (attr.name === "accesskey") { + strings.acceptKey = attr.value; + } + } + for (let attr of searchNo.attributes) { + if (attr.name === "label") { + strings.cancelText = attr.value; + } else if (attr.name === "accesskey") { + strings.cancelKey = attr.value; + } + } this.showDefaultSearchPrompt(browser, strings, icon).then(respond); } @@ -315,13 +323,11 @@ var ExtensionsUI = { // Create a set of formatted strings for a permission prompt _buildStrings(info) { - let bundle = Services.strings.createBundle(BROWSER_PROPERTIES); - - let strings = lazy.ExtensionData.formatPermissionStrings(info, { + const strings = lazy.ExtensionData.formatPermissionStrings(info, { collapseOrigins: true, }); strings.addonName = info.addon.name; - strings.learnMore = bundle.GetStringFromName("webextPerms.learnMore2"); + strings.learnMore = lazy.l10n.formatValueSync("webext-perms-learn-more"); return strings; }, @@ -505,11 +511,10 @@ var ExtensionsUI = { async showInstallNotification(target, addon) { let { window } = getTabBrowser(target); - let bundle = window.gNavigatorBundle; - let message = bundle.getFormattedString("addonPostInstall.message3", [ - "<>", - ]); + const message = await lazy.l10n.formatValue("addon-post-install-message", { + addonName: "<>", + }); const permissionName = "internal:privateBrowsingAllowed"; const { permissions } = await lazy.ExtensionPermissions.get(addon.id); const hasIncognito = permissions.includes(permissionName); diff --git a/python/l10n/fluent_migrations/bug_1793557_extensions.py b/python/l10n/fluent_migrations/bug_1793557_extensions.py index 8cbba693be10..0c04a87509c8 100644 --- a/python/l10n/fluent_migrations/bug_1793557_extensions.py +++ b/python/l10n/fluent_migrations/bug_1793557_extensions.py @@ -18,6 +18,7 @@ def migrate(ctx): browser_properties = "browser/chrome/browser/browser.properties" browser_ftl = "browser/browser/browser.ftl" notifications = "browser/browser/addonNotifications.ftl" + extensions_ui = "browser/browser/extensionsUI.ftl" extensions = "toolkit/toolkit/global/extensions.ftl" permissions = "toolkit/toolkit/global/extensionPermissions.ftl" @@ -437,6 +438,67 @@ def migrate(ctx): ], ) + ctx.add_transforms( + extensions_ui, + extensions_ui, + [ + FTL.Message( + id=FTL.Identifier("webext-perms-learn-more"), + value=COPY(browser_properties, "webextPerms.learnMore2"), + ), + FTL.Message( + id=FTL.Identifier("webext-default-search-description"), + value=REPLACE( + browser_properties, + "webext.defaultSearch.description", + { + "%1$S": VARIABLE_REFERENCE("addonName"), + "%2$S": VARIABLE_REFERENCE("currentEngine"), + "%3$S": VARIABLE_REFERENCE("newEngine"), + }, + ), + ), + FTL.Message( + id=FTL.Identifier("webext-default-search-yes"), + attributes=[ + FTL.Attribute( + id=FTL.Identifier("label"), + value=COPY(browser_properties, "webext.defaultSearchYes.label"), + ), + FTL.Attribute( + id=FTL.Identifier("accesskey"), + value=COPY( + browser_properties, "webext.defaultSearchYes.accessKey" + ), + ), + ], + ), + FTL.Message( + id=FTL.Identifier("webext-default-search-no"), + attributes=[ + FTL.Attribute( + id=FTL.Identifier("label"), + value=COPY(browser_properties, "webext.defaultSearchNo.label"), + ), + FTL.Attribute( + id=FTL.Identifier("accesskey"), + value=COPY( + browser_properties, "webext.defaultSearchNo.accessKey" + ), + ), + ], + ), + FTL.Message( + id=FTL.Identifier("addon-post-install-message"), + value=REPLACE( + browser_properties, + "addonPostInstall.message3", + {"%1$S": VARIABLE_REFERENCE("addonName")}, + ), + ), + ], + ) + ctx.add_transforms( extensions, extensions,