[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torbutton/master] Bug 26100: Migrate general.useragent.locale to intl.locale.requested



commit 399d2ba81505e4a74535b61f60563f4a9c2a8f6d
Author: Igor Oliveira <igt0@xxxxxxxxxxxxxx>
Date:   Wed Feb 28 13:43:48 2018 -0300

    Bug 26100: Migrate general.useragent.locale to intl.locale.requested
    
    intl.locale.requested is the new way that Gecko handles locales.
    See https://bugzilla.mozilla.org/show_bug.cgi?id=1414390
---
 src/chrome/content/aboutTor/aboutTor-content.js |  6 ++++--
 src/chrome/content/menu-overlay.xul             |  2 +-
 src/chrome/content/preferences.js               |  5 ++++-
 src/chrome/content/torbutton.js                 | 10 +++++-----
 src/modules/utils.js                            | 10 ++++++++--
 5 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/chrome/content/aboutTor/aboutTor-content.js b/src/chrome/content/aboutTor/aboutTor-content.js
index ec515bb..1a8d5cf 100644
--- a/src/chrome/content/aboutTor/aboutTor-content.js
+++ b/src/chrome/content/aboutTor/aboutTor-content.js
@@ -67,8 +67,10 @@ var AboutTorListener = {
 
   onPageLoad: function() {
     // Arrange to update localized text and links.
-    bindPrefAndInit("general.useragent.locale", aNewVal => {
-      this.onLocaleChange(aNewVal);
+    bindPrefAndInit("intl.locale.requested", aNewVal => {
+      if (aNewVal !== null) {
+        this.onLocaleChange(aNewVal);
+      }
     });
 
     // Add message and event listeners.
diff --git a/src/chrome/content/menu-overlay.xul b/src/chrome/content/menu-overlay.xul
index 53654c5..f6c6fbd 100644
--- a/src/chrome/content/menu-overlay.xul
+++ b/src/chrome/content/menu-overlay.xul
@@ -22,6 +22,6 @@
               position="1"
               label="&aboutTor.torbrowser_user_manual.label;"
               accesskey="&aboutTor.torbrowser_user_manual.accesskey;"
-              oncommand="gBrowser.selectedTab = gBrowser.addTab('https://tb-manual.torproject.org/' + Services.prefs.getCharPref('general.useragent.locale'))" />
+              oncommand="gBrowser.selectedTab = gBrowser.addTab('https://tb-manual.torproject.org/' + Services.locale.getRequestedLocale())" />
   </menupopup>
 </overlay>
diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index 721ff46..36c8818 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -5,6 +5,9 @@ let { utils: Cu } = Components;
 let { getBoolPref, getIntPref, setBoolPref, setIntPref, getCharPref } =
     Cu.import("resource://gre/modules/Services.jsm", {}).Services.prefs;
 
+let { getLocale } =
+    Cu.import("resource://torbutton/modules/utils.js", {});
+
 // Description elements have the follow names.
 const descNames =
       [, "desc_safest", "desc_safer", "desc_standard"];
@@ -67,7 +70,7 @@ function torbutton_set_learn_more_links() {
   let show_manual = window.opener.torbutton_show_torbrowser_manual();
   let locale = ""
   if (show_manual) {
-    locale = getCharPref('general.useragent.locale');
+    locale = getLocale();
   }
   let links = linkNames.map(name => document.getElementById(name));
   links.forEach(link => {;
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 2f1f689..d744d15 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -10,7 +10,7 @@
 let { LoadContextInfo } = Cu.import('resource://gre/modules/LoadContextInfo.jsm', {});
 let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
 let { showDialog } = Cu.import("resource://torbutton/modules/utils.js", {});
-let { unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js", {});
+let { getLocale, unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js", {});
 let SecurityPrefs = Cu.import("resource://torbutton/modules/security-prefs.js", {});
 let { bindPrefAndInit, observe } = Cu.import("resource://torbutton/modules/utils.js", {});
 
@@ -818,14 +818,14 @@ function torbutton_update_toolbutton()
 // Bug 1506 P3: Support code for language+uagent spoofing
 function torbutton_get_general_useragent_locale() {
    try {
-        var locale = m_tb_prefs.getCharPref("general.useragent.locale");
+        const locale = getLocale();
         if (/chrome:\/\//.test(locale)) {
-            return m_tb_prefs.getComplexValue("general.useragent.locale",
+            return m_tb_prefs.getComplexValue("intl.locale.requested",
                        Components.interfaces.nsIPrefLocalizedString).data;
         }
         return locale;
     } catch(err) {
-        torbutton_log(4, "Error while getting general.useragent.locale:" + err);
+        torbutton_log(4, "Error while getting locale" + err);
         return 'en-US';
     }
 }
@@ -2380,7 +2380,7 @@ function torbutton_show_torbrowser_manual() {
 // torbutton_show_torbrowser_manual() returns true.
 function torbutton_init_user_manual_links() {
   let menuitem = document.getElementById("torBrowserUserManual");
-  bindPrefAndInit("general.useragent.locale", val => {
+  bindPrefAndInit("intl.locale.requested", val => {
     menuitem.hidden = !torbutton_show_torbrowser_manual();
     torbutton_abouttor_message_handler.updateAllOpenPages();
   });
diff --git a/src/modules/utils.js b/src/modules/utils.js
index fa4405e..0a2649d 100644
--- a/src/modules/utils.js
+++ b/src/modules/utils.js
@@ -79,6 +79,12 @@ var getEnv = function (name) {
   return env.exists(name) ? env.get(name) : undefined;
 };
 
+// __getLocale
+// Reads the browser locale, the default locale is en-US.
+var getLocale = function() {
+  return Services.locale.getRequestedLocale() || "en-US";
+}
+
 // ## Windows
 
 // __dialogsByName__.
@@ -200,5 +206,5 @@ var unescapeTorString = function(str) {
 };
 
 // Export utility functions for external use.
-let EXPORTED_SYMBOLS = ["bindPref", "bindPrefAndInit", "getEnv", "getPrefValue",
-                        "observe", "showDialog", "unescapeTorString"];
+let EXPORTED_SYMBOLS = ["bindPref", "bindPrefAndInit", "getEnv", "getLocale",
+                        "getPrefValue", "observe", "showDialog", "unescapeTorString"];



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits