[tbb-commits] [tor-browser] 02/02: squash! Bug 41369: Improve Firefox language settings for multi-lingual packages

gitolite role git at cupani.torproject.org
Tue Nov 15 15:56:14 UTC 2022


This is an automated email from the git hooks/post-receive script.

pierov pushed a commit to branch tor-browser-102.4.0esr-12.0-2
in repository tor-browser.

commit afd362e621f53898a934d6f4bf61d5269095fd18
Author: Pier Angelo Vendrame <pierov at torproject.org>
AuthorDate: Fri Nov 4 18:18:13 2022 +0100

    squash! Bug 41369: Improve Firefox language settings for multi-lingual packages
    
    Bug 41378: Tell users that they can change their language at the first start
    
    With multi-lingual builds, Tor Browser matches the user's system
    language, but some users might want to change it.
    So, we tell them that it is possible, but only once.
---
 browser/base/content/browser.xhtml                 |  2 +
 browser/base/content/languageNotification.js       | 67 ++++++++++++++++++++++
 browser/base/jar.mn                                |  2 +
 browser/components/preferences/main.inc.xhtml      |  2 +-
 .../locales/en-US/browser/languageNotification.ftl | 10 ++++
 5 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/browser/base/content/browser.xhtml b/browser/base/content/browser.xhtml
index 6a9103f4e16e..ac4ddb8c3979 100644
--- a/browser/base/content/browser.xhtml
+++ b/browser/base/content/browser.xhtml
@@ -95,6 +95,7 @@
 #ifdef NIGHTLY_BUILD
   <link rel="localization" href="preview/firefoxView.ftl"/>
 #endif
+  <link rel="localization" href="browser/languageNotification.ftl"/>
 
   <title data-l10n-id="browser-main-window-title"></title>
 
@@ -122,6 +123,7 @@
   Services.scriptloader.loadSubScript("chrome://browser/content/places/places-menupopup.js", this);
   Services.scriptloader.loadSubScript("chrome://browser/content/search/autocomplete-popup.js", this);
   Services.scriptloader.loadSubScript("chrome://browser/content/search/searchbar.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/languageNotification.js", this);
   Services.scriptloader.loadSubScript("chrome://torbutton/content/tor-circuit-display.js", this);
   Services.scriptloader.loadSubScript("chrome://torbutton/content/torbutton.js", this);
   Services.scriptloader.loadSubScript("chrome://browser/content/torconnect/torBootstrapUrlbar.js", this);
diff --git a/browser/base/content/languageNotification.js b/browser/base/content/languageNotification.js
new file mode 100644
index 000000000000..73a5da0b58aa
--- /dev/null
+++ b/browser/base/content/languageNotification.js
@@ -0,0 +1,67 @@
+"use strict";
+
+// Show a prompt to suggest to the user that they can change the UI language.
+// Show it only the first time, and then do not show it anymore
+window.addEventListener("load", async () => {
+  const PREF_NAME = "intl.language_notification.shown";
+
+  if (Services.prefs.getBoolPref(PREF_NAME, false)) {
+    return;
+  }
+
+  // Already customized, we do not suggest to change it again...
+  if (Services.prefs.getCharPref("intl.locale.requested", "") !== "") {
+    // ... and we never show the notification, either
+    Services.prefs.setBoolPref(PREF_NAME, true);
+    return;
+  }
+
+  // In sync with our changes on browser/components/preferences/main.js for
+  // tor-browser#41369 and tor-browser#41372.
+  const code =
+    Services.locale.appLocaleAsBCP47 === "ja-JP-macos"
+      ? "ja"
+      : Services.locale.appLocaleAsBCP47;
+  const language = Services.intl
+    .getLocaleDisplayNames(undefined, [code], { preferNative: true })[0]
+    .replace(/\s*\(.+\)$/g, "");
+
+  // We want to determine whether the current locale was chosen based on the
+  // system locales, in which case langauge negotiation returns a match, or
+  // whether it simply defaulted to en-US.
+  const matchingSystem = !!Services.locale.negotiateLanguages(
+    // Since intl.locale.requested is empty, we expect requestedLocales to match
+    // the user's system locales.
+    Services.locale.requestedLocales,
+    Services.locale.availableLocales
+  ).length;
+  const label = await document.l10n.formatValue(
+    matchingSystem
+      ? "language-notification-label-system"
+      : "language-notification-label",
+    { language }
+  );
+
+  const buttons = [
+    {
+      "l10n-id": "language-notification-button",
+      callback() {
+        openPreferences("general-language");
+      },
+    },
+  ];
+
+  gNotificationBox.appendNotification(
+    "language-notification",
+    {
+      label,
+      priority: gNotificationBox.PRIORITY_INFO_HIGH,
+    },
+    buttons
+  );
+
+  // We do not wait for the user to either click on the button or dismiss the
+  // notification: after we have shown it once, we take for granted that the
+  // user has seen it and we never show it again.
+  Services.prefs.setBoolPref(PREF_NAME, true);
+});
diff --git a/browser/base/jar.mn b/browser/base/jar.mn
index 02ee0b359515..5b603d0d5483 100644
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -111,6 +111,8 @@ browser.jar:
         content/browser/spotlight.js                  (content/spotlight.js)
 *       content/browser/default-bookmarks.html        (content/default-bookmarks.html)
 
+        content/browser/languageNotification.js       (content/languageNotification.js)
+
 % override chrome://global/content/netError.xhtml chrome://browser/content/certerror/aboutNetError.xhtml
 
 # L10n resources and overrides.
diff --git a/browser/components/preferences/main.inc.xhtml b/browser/components/preferences/main.inc.xhtml
index c4ada41e3d75..7c750203fb54 100644
--- a/browser/components/preferences/main.inc.xhtml
+++ b/browser/components/preferences/main.inc.xhtml
@@ -322,7 +322,7 @@
 </groupbox>
 
 <!-- Languages -->
-<groupbox id="languagesGroup" data-category="paneGeneral" hidden="true">
+<groupbox id="languagesGroup" data-category="paneGeneral" hidden="true" data-subcategory="language">
   <label><html:h2 data-l10n-id="language-header"/></label>
 
   <vbox id="browserLanguagesBox" align="start" hidden="true">
diff --git a/browser/locales/en-US/browser/languageNotification.ftl b/browser/locales/en-US/browser/languageNotification.ftl
new file mode 100644
index 000000000000..2ad06bf5c2d5
--- /dev/null
+++ b/browser/locales/en-US/browser/languageNotification.ftl
@@ -0,0 +1,10 @@
+# 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/.
+
+# $language is the language Tor Browser is displayed in (already translated)
+language-notification-label-system = { -brand-short-name } has set your display language to { $language } based on your system’s language.
+# This is shown when the system language is not supported, so we fall back to another language instead.
+# $language is the language Tor Browser is displayed in (already translated).
+language-notification-label = { -brand-short-name } has set your display language to { $language }.
+language-notification-button = Change Language…

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list