From 27ed680c0ba1f8c8662b85baec259c5aff15b1b2 Mon Sep 17 00:00:00 2001 From: Greg Tatum Date: Wed, 30 Mar 2022 20:12:10 +0000 Subject: [PATCH] Bug 1760825 - Fix New Tab text to change on a live language reload; r=amy This text is cached, and so needs invalidating when the app locale is changed. Differential Revision: https://phabricator.services.mozilla.com/D142256 --- browser/base/content/tabbrowser-tabs.js | 36 ++++++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/browser/base/content/tabbrowser-tabs.js b/browser/base/content/tabbrowser-tabs.js index 90d6b5964373..a7b35dd2cb26 100644 --- a/browser/base/content/tabbrowser-tabs.js +++ b/browser/base/content/tabbrowser-tabs.js @@ -61,13 +61,9 @@ ); this._hiddenSoundPlayingTabs = new Set(); - // Normal tab title is used also in the permanent private browsing mode. - let strId = - PrivateBrowsingUtils.isWindowPrivate(window) && - !Services.prefs.getBoolPref("browser.privatebrowsing.autostart") - ? "emptyPrivateTabTitle" - : "emptyTabTitle"; - this.emptyTabTitle = gTabBrowserBundle.GetStringFromName("tabs." + strId); + this.emptyTabTitle = gTabBrowserBundle.GetStringFromName( + this.getTabTitleMessageId() + ); var tab = this.allTabs[0]; tab.label = this.emptyTabTitle; @@ -100,6 +96,7 @@ this.boundObserve = (...args) => this.observe(...args); Services.prefs.addObserver("privacy.userContext", this.boundObserve); + Services.obs.addObserver(this.boundObserve, "intl:app-locales-changed"); this.observe(null, "nsPref:changed", "privacy.userContext.enabled"); XPCOMUtils.defineLazyPreferenceGetter( @@ -999,6 +996,14 @@ event.stopPropagation(); } + getTabTitleMessageId() { + // Normal tab title is used also in the permanent private browsing mode. + return PrivateBrowsingUtils.isWindowPrivate(window) && + !Services.prefs.getBoolPref("browser.privatebrowsing.autostart") + ? "tabs.emptyPrivateTabTitle" + : "tabs.emptyTabTitle"; + } + get tabbox() { return document.getElementById("tabbrowser-tabbox"); } @@ -1171,6 +1176,19 @@ } break; + + case "intl:app-locales-changed": + document.l10n.ready.then(() => { + // The cached emptyTabTitle needs updating, create a new string bundle + // here to ensure the latest locale string is used. + const bundle = Services.strings.createBundle( + "chrome://browser/locale/tabbrowser.properties" + ); + this.emptyTabTitle = bundle.GetStringFromName( + this.getTabTitleMessageId() + ); + }); + break; } } @@ -2144,6 +2162,10 @@ destroy() { if (this.boundObserve) { Services.prefs.removeObserver("privacy.userContext", this.boundObserve); + Services.obs.removeObserver( + this.boundObserve, + "intl:app-locales-changed" + ); } CustomizableUI.removeListener(this);