Bug 1162283 - Add support for limited hard-coded localizations to Pocket. r=dolske, a=dolske
authorDrew Willcoxon <adw@mozilla.com>
Fri, 08 May 2015 18:57:08 -0700
changeset 260449 e7c47480555d
parent 260448 a1c5d7a6a784
child 260450 86e98ffc152b
push id784
push userjdolske@mozilla.com
push date2015-05-11 00:19 +0000
treeherdermozilla-release@32b69592b334 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske, dolske
bugs1162283
milestone38.0
Bug 1162283 - Add support for limited hard-coded localizations to Pocket. r=dolske, a=dolske
browser/base/content/browser-places.js
browser/base/content/browser-pocket-de.properties
browser/base/content/browser-pocket-es-ES.properties
browser/base/content/browser-pocket-ja.properties
browser/base/content/browser-pocket-ru.properties
browser/base/content/browser-pocket.properties
browser/base/content/nsContextMenu.js
browser/base/jar.mn
browser/components/customizableui/CustomizableWidgets.jsm
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1427,16 +1427,31 @@ let BookmarkingUI = {
 
   onMainMenuPopupShowing: function BUI_onMainMenuPopupShowing(event) {
     this._updateBookmarkPageMenuItem();
     PlacesCommandHook.updateBookmarkAllTabsCommand();
   },
 
   updatePocketItemVisibility: function BUI_updatePocketItemVisibility(prefix) {
     let hidden = !CustomizableUI.getPlacementOfWidget("pocket-button");
+    if (!hidden) {
+      let locale = Cc["@mozilla.org/chrome/chrome-registry;1"].
+                   getService(Ci.nsIXULChromeRegistry).
+                   getSelectedLocale("browser");
+      let url = "chrome://browser/content/browser-pocket-" + locale + ".properties";
+      let bundle = Services.strings.createBundle(url);
+      let item = document.getElementById(prefix + "pocket");
+      try {
+        item.setAttribute("label", bundle.GetStringFromName("pocketMenuitem.label"));
+      } catch (err) {
+        // GetStringFromName throws when the bundle doesn't exist.  In that
+        // case, the item will retain the browser-pocket.dtd en-US string that
+        // it has in the markup.
+      }
+    }
     document.getElementById(prefix + "pocket").hidden = hidden;
     document.getElementById(prefix + "pocketSeparator").hidden = hidden;
   },
 
   _showBookmarkedNotification: function BUI_showBookmarkedNotification() {
     function getCenteringTransformForRects(rectToPosition, referenceRect) {
       let topDiff = referenceRect.top - rectToPosition.top;
       let leftDiff = referenceRect.left - rectToPosition.left;
new file mode 100644
--- /dev/null
+++ b/browser/base/content/browser-pocket-de.properties
@@ -0,0 +1,14 @@
+# 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/.
+
+# This is a temporary file, later versions of Firefox will use
+# browser.properties in the usual L10N location.
+
+pocket-button.label = Pocket
+pocket-button.tooltiptext = Bei Pocket speichern
+
+# From browser-pocket.dtd
+saveToPocketCmd.label = Seite bei Pocket speichern
+saveToPocketCmd.accesskey = k
+pocketMenuitem.label = Pocket-Liste anzeigen
new file mode 100644
--- /dev/null
+++ b/browser/base/content/browser-pocket-es-ES.properties
@@ -0,0 +1,14 @@
+# 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/.
+
+# This is a temporary file, later versions of Firefox will use
+# browser.properties in the usual L10N location.
+
+pocket-button.label = Pocket
+pocket-button.tooltiptext = Guardar en Pocket
+
+# From browser-pocket.dtd
+saveToPocketCmd.label = Guardar página en Pocket
+saveToPocketCmd.accesskey = k
+pocketMenuitem.label = Ver lista de Pocket
new file mode 100644
--- /dev/null
+++ b/browser/base/content/browser-pocket-ja.properties
@@ -0,0 +1,14 @@
+# 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/.
+
+# This is a temporary file, later versions of Firefox will use
+# browser.properties in the usual L10N location.
+
+pocket-button.label = Pocket
+pocket-button.tooltiptext = Pocket に保存
+
+# From browser-pocket.dtd
+saveToPocketCmd.label = Pocket にページを保存
+saveToPocketCmd.accesskey = k
+pocketMenuitem.label = Pocket のマイリストを表示
new file mode 100644
--- /dev/null
+++ b/browser/base/content/browser-pocket-ru.properties
@@ -0,0 +1,14 @@
+# 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/.
+
+# This is a temporary file, later versions of Firefox will use
+# browser.properties in the usual L10N location.
+
+pocket-button.label = Pocket
+pocket-button.tooltiptext = Сохранить в Pocket
+
+# From browser-pocket.dtd
+saveToPocketCmd.label = Сохранить страницу в Pocket
+saveToPocketCmd.accesskey = х
+pocketMenuitem.label = Показать список Pocket
--- a/browser/base/content/browser-pocket.properties
+++ b/browser/base/content/browser-pocket.properties
@@ -1,9 +1,9 @@
 # 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/.
 
-# This is a temporary file and not meant for localization; later versions
-# of Firefox include these strings in browser.properties
+# This is a temporary file, later versions of Firefox will use
+# browser.properties in the usual L10N location.
 
 pocket-button.label = Pocket
 pocket-button.tooltiptext = Save to Pocket
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -232,16 +232,32 @@ nsContextMenu.prototype = {
     let canPocket = false;
     if (shouldShow && window.gBrowser &&
         this.browser.getTabBrowser() == window.gBrowser) {
       let uri = this.browser.currentURI;
       canPocket =
         CustomizableUI.getPlacementOfWidget("pocket-button") &&
         (uri.schemeIs("http") || uri.schemeIs("https") ||
          (uri.schemeIs("about") && ReaderMode.getOriginalUrl(uri.spec)));
+      if (canPocket) {
+        let locale = Cc["@mozilla.org/chrome/chrome-registry;1"].
+                     getService(Ci.nsIXULChromeRegistry).
+                     getSelectedLocale("browser");
+        let url = "chrome://browser/content/browser-pocket-" + locale + ".properties";
+        let bundle = Services.strings.createBundle(url);
+        let item = document.getElementById("context-pocket");
+        try {
+          item.setAttribute("label", bundle.GetStringFromName("saveToPocketCmd.label"));
+          item.setAttribute("accesskey", bundle.GetStringFromName("saveToPocketCmd.accesskey"));
+        } catch (err) {
+          // GetStringFromName throws when the bundle doesn't exist.  In that
+          // case, the item will retain the browser-pocket.dtd en-US string that
+          // it has in the markup.
+        }
+      }
     }
     this.showItem("context-pocket", canPocket && window.pktApi && window.pktApi.isUserLoggedIn());
   },
 
   initViewItems: function CM_initViewItems() {
     // View source is always OK, unless in directory listing.
     this.showItem("context-viewpartialsource-selection",
                   this.isContentSelected);
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -72,16 +72,20 @@ browser.jar:
         content/browser/aboutTabCrashed.css           (content/aboutTabCrashed.css)
         content/browser/aboutTabCrashed.js            (content/aboutTabCrashed.js)
         content/browser/aboutTabCrashed.xhtml         (content/aboutTabCrashed.xhtml)
 *       content/browser/browser.css                   (content/browser.css)
 *       content/browser/browser.js                    (content/browser.js)
 *       content/browser/browser.xul                   (content/browser.xul)
         content/browser/browser-pocket.properties     (content/browser-pocket.properties)
         content/browser/browser-pocket.dtd            (content/browser-pocket.dtd)
+        content/browser/browser-pocket-de.properties  (content/browser-pocket-de.properties)
+        content/browser/browser-pocket-es-ES.properties (content/browser-pocket-es-ES.properties)
+        content/browser/browser-pocket-ja.properties  (content/browser-pocket-ja.properties)
+        content/browser/browser-pocket-ru.properties  (content/browser-pocket-ru.properties)
 *       content/browser/browser-tabPreviews.xml       (content/browser-tabPreviews.xml)
 *       content/browser/chatWindow.xul                (content/chatWindow.xul)
         content/browser/content.js                    (content/content.js)
         content/browser/defaultthemes/1.footer.jpg    (content/defaultthemes/1.footer.jpg)
         content/browser/defaultthemes/1.header.jpg    (content/defaultthemes/1.header.jpg)
         content/browser/defaultthemes/1.icon.jpg      (content/defaultthemes/1.icon.jpg)
         content/browser/defaultthemes/1.preview.jpg   (content/defaultthemes/1.preview.jpg)
         content/browser/defaultthemes/2.footer.jpg    (content/defaultthemes/2.footer.jpg)
--- a/browser/components/customizableui/CustomizableWidgets.jsm
+++ b/browser/components/customizableui/CustomizableWidgets.jsm
@@ -34,20 +34,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyGetter(this, "CharsetBundle", function() {
   const kCharsetBundle = "chrome://global/locale/charsetMenu.properties";
   return Services.strings.createBundle(kCharsetBundle);
 });
 XPCOMUtils.defineLazyGetter(this, "BrandBundle", function() {
   const kBrandBundle = "chrome://branding/locale/brand.properties";
   return Services.strings.createBundle(kBrandBundle);
 });
-XPCOMUtils.defineLazyGetter(this, "PocketBundle", function() {
-  const kPocketBundle = "chrome://browser/content/browser-pocket.properties";
-  return Services.strings.createBundle(kPocketBundle);
-});
 
 const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const kPrefCustomizationDebug = "browser.uiCustomization.debug";
 const kWidePanelItemClass = "panel-wide-item";
 
 let gModuleName = "[CustomizableWidgets]";
 #include logging.js
 
@@ -1062,38 +1058,55 @@ if (Services.prefs.getBoolPref("privacy.
       let forgetButton = aEvent.target.querySelector("#PanelUI-panic-view-button");
       forgetButton.removeEventListener("command", this);
     },
   });
 }
 
 if (Services.prefs.getBoolPref("browser.pocket.enabled")) {
   let isEnabledForLocale = true;
+  let browserLocale;
   if (Services.prefs.getBoolPref("browser.pocket.useLocaleList")) {
     let chromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"]
                            .getService(Ci.nsIXULChromeRegistry);
-    let browserLocale = chromeRegistry.getSelectedLocale("browser");
+    browserLocale = chromeRegistry.getSelectedLocale("browser");
     let enabledLocales = [];
     try {
       enabledLocales = Services.prefs.getCharPref("browser.pocket.enabledLocales").split(' ');
     } catch (ex) {
       Cu.reportError(ex);
     }
     isEnabledForLocale = enabledLocales.indexOf(browserLocale) != -1;
   }
 
   if (isEnabledForLocale) {
+    let url = "chrome://browser/content/browser-pocket-" + browserLocale + ".properties";
+    let strings = Services.strings.createBundle(url);
+    let label;
+    let tooltiptext;
+    try {
+      label = strings.GetStringFromName("pocket-button.label");
+      tooltiptext = strings.GetStringFromName("pocket-button.tooltiptext");
+    } catch (err) {
+      // GetStringFromName throws when the bundle doesn't exist.  In that case,
+      // fall back to the en-US browser-pocket.properties.
+      url = "chrome://browser/content/browser-pocket.properties";
+      strings = Services.strings.createBundle(url);
+      label = strings.GetStringFromName("pocket-button.label");
+      tooltiptext = strings.GetStringFromName("pocket-button.tooltiptext");
+    }
+
     let pocketButton = {
       id: "pocket-button",
       defaultArea: CustomizableUI.AREA_NAVBAR,
       introducedInVersion: "pref",
       type: "view",
       viewId: "PanelUI-pocketView",
-      label: PocketBundle.GetStringFromName("pocket-button.label"),
-      tooltiptext: PocketBundle.GetStringFromName("pocket-button.tooltiptext"),
+      label: label,
+      tooltiptext: tooltiptext,
       onViewShowing: Pocket.onPanelViewShowing,
       onViewHiding: Pocket.onPanelViewHiding,
 
       // If the user has the "classic" Pocket add-on installed, use that instead
       // and destroy the widget.
       conditionalDestroyPromise: new Promise(resolve => {
         AddonManager.getAddonByID("isreaditlater@ideashower.com", addon => {
           resolve(addon && addon.isActive);