From 311fa7e378205a9cb1093a80d09dd2ff60141997 Mon Sep 17 00:00:00 2001 From: Drew Willcoxon Date: Tue, 28 Jul 2020 15:33:01 +0000 Subject: [PATCH] Bug 1655672 - Fix l10n for one-off tooltips with aliases. r=harry,fluent-reviewers,flod Differential Revision: https://phabricator.services.mozilla.com/D85125 --- browser/components/search/SearchOneOffs.jsm | 16 +++++------ .../components/urlbar/UrlbarSearchOneOffs.jsm | 28 +++++++++++-------- browser/locales/en-US/browser/browser.ftl | 7 +++++ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/browser/components/search/SearchOneOffs.jsm b/browser/components/search/SearchOneOffs.jsm index 148c0cd16415..b132b19ffad3 100644 --- a/browser/components/search/SearchOneOffs.jsm +++ b/browser/components/search/SearchOneOffs.jsm @@ -515,6 +515,7 @@ class SearchOneOffs { for (let i = 0; i < engines.length; ++i) { let engine = engines[i]; let button = this.document.createXULElement("button"); + button.engine = engine; button.id = this._buttonIDForEngine(engine); let uri = "chrome://browser/skin/search-engine-placeholder.png"; if (engine.iconURI) { @@ -522,8 +523,7 @@ class SearchOneOffs { } button.setAttribute("image", uri); button.setAttribute("class", "searchbar-engine-one-off-item"); - button.setAttribute("tooltiptext", this.tooltipForEngine(engine)); - button.engine = engine; + this.setTooltipForEngineButton(button); this.buttons.appendChild(button); } @@ -1094,14 +1094,14 @@ class SearchOneOffs { } /** - * Gets the tooltip for the one-off button of an engine. + * Sets the tooltip for a one-off button with an engine. This should set + * either the `tooltiptext` attribute or the relevant l10n ID. * - * @param {nsISearchEngine|SearchEngine} engine - * The engine. - * @returns {string} The tooltip for the given engine. + * @param {element} button + * The one-off button. */ - tooltipForEngine(engine) { - return engine.name; + setTooltipForEngineButton(button) { + button.setAttribute("tooltiptext", button.engine.name); } // Event handlers below. diff --git a/browser/components/urlbar/UrlbarSearchOneOffs.jsm b/browser/components/urlbar/UrlbarSearchOneOffs.jsm index 089fa13179c3..3db180fe25e0 100644 --- a/browser/components/urlbar/UrlbarSearchOneOffs.jsm +++ b/browser/components/urlbar/UrlbarSearchOneOffs.jsm @@ -129,19 +129,25 @@ class UrlbarSearchOneOffs extends SearchOneOffs { } /** - * Gets the tooltip for the one-off button of an engine. + * Sets the tooltip for a one-off button with an engine. This should set + * either the `tooltiptext` attribute or the relevant l10n ID. * - * @param {nsISearchEngine|SearchEngine} engine - * The engine. - * @returns {string} - * The tooltip for the given engine. + * @param {element} button + * The one-off button. */ - tooltipForEngine(engine) { - let tooltip = engine.name; - let aliases = UrlbarSearchUtils.aliasesForEngine(engine); - if (aliases.length) { - tooltip += ` (${aliases[0]})`; + setTooltipForEngineButton(button) { + let aliases = UrlbarSearchUtils.aliasesForEngine(button.engine); + if (!aliases.length) { + super.setTooltipForEngineButton(button); + return; } - return tooltip; + this.document.l10n.setAttributes( + button, + "search-one-offs-engine-with-alias", + { + engineName: button.engine.name, + alias: aliases[0], + } + ); } } diff --git a/browser/locales/en-US/browser/browser.ftl b/browser/locales/en-US/browser/browser.ftl index 965759071612..d10e269a5852 100644 --- a/browser/locales/en-US/browser/browser.ftl +++ b/browser/locales/en-US/browser/browser.ftl @@ -190,6 +190,13 @@ search-one-offs-context-set-as-default-private = .label = Set as Default Search Engine for Private Windows .accesskey = P +# Search engine one-off buttons with an @alias shortcut/keyword. +# Variables: +# $engineName (String): The name of the engine. +# $alias (String): The @alias shortcut/keyword. +search-one-offs-engine-with-alias = + .tooltiptext = { $engineName } ({ $alias }) + ## Bookmark Panel bookmark-panel-show-editor-checkbox =