From 7fa5435add1d1ab9936c37d41d541f161855fc1e Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Tue, 22 Nov 2022 17:12:23 +0000 Subject: [PATCH] Bug 1760029 - Migrate tabbrowser.properties strings used by OpenInTabsUtils.jsm to Fluent. r=dao,fluent-reviewers,flod Differential Revision: https://phabricator.services.mozilla.com/D159020 --- browser/locales/en-US/browser/tabbrowser.ftl | 12 ++++++ .../chrome/browser/tabbrowser.properties | 8 ---- browser/modules/OpenInTabsUtils.jsm | 40 ++++++++----------- .../bug_1760029_tabbrowser.py | 39 ++++++++++++++++++ 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/browser/locales/en-US/browser/tabbrowser.ftl b/browser/locales/en-US/browser/tabbrowser.ftl index 3d4fdca5f019..8da32466ceca 100644 --- a/browser/locales/en-US/browser/tabbrowser.ftl +++ b/browser/locales/en-US/browser/tabbrowser.ftl @@ -107,6 +107,18 @@ tabbrowser-confirm-close-tabs-with-key-button = Quit { -brand-short-name } # $quitKey (String): the text of the keyboard shortcut for quitting. tabbrowser-confirm-close-tabs-with-key-checkbox = Confirm before quitting with { $quitKey } +## Confirmation dialog when opening multiple tabs simultaneously + +tabbrowser-confirm-open-multiple-tabs-title = Confirm open +# Variables: +# $tabCount (Number): The number of tabs that will be opened. +tabbrowser-confirm-open-multiple-tabs-message = + { $tabCount -> + *[other] You are about to open { $tabCount } tabs. This might slow down { -brand-short-name } while the pages are loading. Are you sure you want to continue? + } +tabbrowser-confirm-open-multiple-tabs-button = Open tabs +tabbrowser-confirm-open-multiple-tabs-checkbox = Warn me when opening multiple tabs might slow down { -brand-short-name } + ## Confirmation dialog for enabling caret browsing tabbrowser-confirm-caretbrowsing-title = Caret Browsing diff --git a/browser/locales/en-US/chrome/browser/tabbrowser.properties b/browser/locales/en-US/chrome/browser/tabbrowser.properties index ea5952332841..6fbe8159b2db 100644 --- a/browser/locales/en-US/chrome/browser/tabbrowser.properties +++ b/browser/locales/en-US/chrome/browser/tabbrowser.properties @@ -1,11 +1,3 @@ # 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/. - -# LOCALIZATION NOTE (tabs.openWarningTitle, tabs.openWarningMultipleBranded, tabs.openButtonMultiple, tabs.openWarningPromptMeBranded): -# These items are moved from chrome/browser/places/places.properties -# Now they are not specific to bookmark. -tabs.openWarningTitle=Confirm open -tabs.openWarningMultipleBranded=You are about to open %S tabs. This might slow down %S while the pages are loading. Are you sure you want to continue? -tabs.openButtonMultiple=Open tabs -tabs.openWarningPromptMeBranded=Warn me when opening multiple tabs might slow down %S diff --git a/browser/modules/OpenInTabsUtils.jsm b/browser/modules/OpenInTabsUtils.jsm index 6778df0a5762..c080dd111227 100644 --- a/browser/modules/OpenInTabsUtils.jsm +++ b/browser/modules/OpenInTabsUtils.jsm @@ -12,9 +12,10 @@ const { XPCOMUtils } = ChromeUtils.importESModule( const lazy = {}; -XPCOMUtils.defineLazyGetter(lazy, "bundle", function() { - return Services.strings.createBundle( - "chrome://browser/locale/tabbrowser.properties" +XPCOMUtils.defineLazyGetter(lazy, "l10n", () => { + return new Localization( + ["browser/tabbrowser.ftl", "branding/brand.ftl"], + true ); }); @@ -23,14 +24,6 @@ XPCOMUtils.defineLazyGetter(lazy, "bundle", function() { * called without any tabbrowser instance. */ const OpenInTabsUtils = { - getString(key) { - return lazy.bundle.GetStringFromName(key); - }, - - getFormattedString(key, params) { - return lazy.bundle.formatStringFromName(key, params); - }, - /** * Gives the user a chance to cancel loading lots of tabs at once. */ @@ -47,25 +40,26 @@ const OpenInTabsUtils = { // default to true: if it were false, we wouldn't get this far let warnOnOpen = { value: true }; - const messageKey = "tabs.openWarningMultipleBranded"; - const openKey = "tabs.openButtonMultiple"; - const BRANDING_BUNDLE_URI = "chrome://branding/locale/brand.properties"; - let brandShortName = Services.strings - .createBundle(BRANDING_BUNDLE_URI) - .GetStringFromName("brandShortName"); + const [title, message, button, checkbox] = lazy.l10n.formatMessagesSync([ + { id: "tabbrowser-confirm-open-multiple-tabs-title" }, + { + id: "tabbrowser-confirm-open-multiple-tabs-message", + args: { tabCount: numTabsToOpen }, + }, + { id: "tabbrowser-confirm-open-multiple-tabs-button" }, + { id: "tabbrowser-confirm-open-multiple-tabs-checkbox" }, + ]); let buttonPressed = Services.prompt.confirmEx( aWindow, - this.getString("tabs.openWarningTitle"), - this.getFormattedString(messageKey, [numTabsToOpen, brandShortName]), + title.value, + message.value, Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 + Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1, - this.getString(openKey), + button.value, null, null, - this.getFormattedString("tabs.openWarningPromptMeBranded", [ - brandShortName, - ]), + checkbox.value, warnOnOpen ); diff --git a/python/l10n/fluent_migrations/bug_1760029_tabbrowser.py b/python/l10n/fluent_migrations/bug_1760029_tabbrowser.py index 90cf75ecb67f..9fe8cf3a7d75 100644 --- a/python/l10n/fluent_migrations/bug_1760029_tabbrowser.py +++ b/python/l10n/fluent_migrations/bug_1760029_tabbrowser.py @@ -248,6 +248,45 @@ def migrate(ctx): {"%1$S": VARIABLE_REFERENCE("quitKey")}, ), ), + FTL.Message( + id=FTL.Identifier("tabbrowser-confirm-open-multiple-tabs-title"), + value=COPY(source, "tabs.openWarningTitle"), + ), + FTL.Message( + id=FTL.Identifier("tabbrowser-confirm-open-multiple-tabs-message"), + value=Transform.pattern_of( + FTL.SelectExpression( + selector=VARIABLE_REFERENCE("tabCount"), + variants=[ + FTL.Variant( + key=FTL.Identifier("other"), + value=REPLACE( + source, + "tabs.openWarningMultipleBranded", + { + "%1$S": VARIABLE_REFERENCE("tabCount"), + "%2$S": TERM_REFERENCE("brand-short-name"), + ". ": FTL.TextElement(". "), + }, + ), + default=True, + ), + ], + ) + ), + ), + FTL.Message( + id=FTL.Identifier("tabbrowser-confirm-open-multiple-tabs-button"), + value=COPY(source, "tabs.openButtonMultiple"), + ), + FTL.Message( + id=FTL.Identifier("tabbrowser-confirm-open-multiple-tabs-checkbox"), + value=REPLACE( + source, + "tabs.openWarningPromptMeBranded", + {"%1$S": TERM_REFERENCE("brand-short-name")}, + ), + ), FTL.Message( id=FTL.Identifier("tabbrowser-confirm-caretbrowsing-title"), value=COPY(source, "browsewithcaret.checkWindowTitle"),