Bug 824243 - Make Profiler UI localizable, r=robcee
authorAnton Kovalyov <anton@mozilla.com>
Thu, 31 Jan 2013 11:40:11 -0800
changeset 120477 44772e261a55070796a716202738cd52bd5700b5
parent 120476 73ccb94a810dde1a682db52491a8a55ba706b61f
child 120478 a4f8cb70cc5d1949fdcf2b1347c4bd43494a06bd
push idunknown
push userunknown
push dateunknown
reviewersrobcee
bugs824243
milestone21.0a1
Bug 824243 - Make Profiler UI localizable, r=robcee
browser/devtools/jar.mn
browser/devtools/profiler/ProfilerHelpers.jsm
browser/devtools/profiler/ProfilerPanel.jsm
browser/devtools/profiler/cleopatra/cleopatra.html
browser/devtools/profiler/cleopatra/js/devtools.js
browser/devtools/profiler/cleopatra/js/strings.js
browser/devtools/profiler/cleopatra/js/ui.js
browser/devtools/profiler/profiler.xul
browser/locales/en-US/chrome/browser/devtools/profiler.dtd
browser/locales/en-US/chrome/browser/devtools/profiler.properties
browser/locales/jar.mn
--- a/browser/devtools/jar.mn
+++ b/browser/devtools/jar.mn
@@ -28,16 +28,17 @@ browser.jar:
     content/browser/debugger-toolbar.js           (debugger/debugger-toolbar.js)
     content/browser/debugger-panes.js             (debugger/debugger-panes.js)
     content/browser/profiler.xul                  (profiler/profiler.xul)
     content/browser/profiler.css                  (profiler/profiler.css)
     content/browser/devtools/cleopatra.html       (profiler/cleopatra/cleopatra.html)
     content/browser/devtools/profiler/cleopatra/css/ui.css              (profiler/cleopatra/css/ui.css)
     content/browser/devtools/profiler/cleopatra/css/tree.css            (profiler/cleopatra/css/tree.css)
     content/browser/devtools/profiler/cleopatra/css/devtools.css        (profiler/cleopatra/css/devtools.css)
+    content/browser/devtools/profiler/cleopatra/js/strings.js           (profiler/cleopatra/js/strings.js)
     content/browser/devtools/profiler/cleopatra/js/parser.js            (profiler/cleopatra/js/parser.js)
     content/browser/devtools/profiler/cleopatra/js/parserWorker.js      (profiler/cleopatra/js/parserWorker.js)
     content/browser/devtools/profiler/cleopatra/js/tree.js              (profiler/cleopatra/js/tree.js)
     content/browser/devtools/profiler/cleopatra/js/ui.js                (profiler/cleopatra/js/ui.js)
     content/browser/devtools/profiler/cleopatra/js/ProgressReporter.js  (profiler/cleopatra/js/ProgressReporter.js)
     content/browser/devtools/profiler/cleopatra/js/devtools.js          (profiler/cleopatra/js/devtools.js)
     content/browser/devtools/profiler/cleopatra/images/circlearrow.svg  (profiler/cleopatra/images/circlearrow.svg)
     content/browser/devtools/profiler/cleopatra/images/noise.png        (profiler/cleopatra/images/noise.png)
new file mode 100644
--- /dev/null
+++ b/browser/devtools/profiler/ProfilerHelpers.jsm
@@ -0,0 +1,43 @@
+/* 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/. */
+
+"use strict";
+
+const Cu = Components.utils;
+const ProfilerProps = "chrome://browser/locale/devtools/profiler.properties";
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+this.EXPORTED_SYMBOLS = ["L10N"];
+
+/**
+ * Localization helper methods.
+ */
+let L10N = {
+  /**
+   * Returns a simple localized string.
+   *
+   * @param string name
+   * @return string
+   */
+  getStr: function L10N_getStr(name) {
+    return this.stringBundle.GetStringFromName(name);
+  },
+
+  /**
+   * Returns formatted localized string.
+   *
+   * @param string name
+   * @param array params
+   * @return string
+   */
+  getFormatStr: function L10N_getFormatStr(name, params) {
+    return this.stringBundle.formatStringFromName(name, params, params.length);
+  }
+};
+
+XPCOMUtils.defineLazyGetter(L10N, "stringBundle", function () {
+  return Services.strings.createBundle(ProfilerProps);
+});
\ No newline at end of file
--- a/browser/devtools/profiler/ProfilerPanel.jsm
+++ b/browser/devtools/profiler/ProfilerPanel.jsm
@@ -2,16 +2,17 @@
  * 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/. */
 
 "use strict";
 
 const Cu = Components.utils;
 
 Cu.import("resource:///modules/devtools/ProfilerController.jsm");
+Cu.import("resource:///modules/devtools/ProfilerHelpers.jsm");
 Cu.import("resource://gre/modules/commonjs/promise/core.js");
 Cu.import("resource:///modules/devtools/EventEmitter.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 this.EXPORTED_SYMBOLS = ["ProfilerPanel"];
 
 XPCOMUtils.defineLazyGetter(this, "DebuggerServer", function () {
   Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
@@ -244,22 +245,21 @@ ProfilerPanel.prototype = {
     let uid  = ++this._uid;
     let list = this.document.getElementById("profiles-list");
     let item = this.document.createElement("li");
     let wrap = this.document.createElement("h1");
 
     item.setAttribute("id", "profile-" + uid);
     item.setAttribute("data-uid", uid);
     item.addEventListener("click", function (ev) {
-      let uid = parseInt(ev.target.getAttribute("data-uid"), 10);
       this.switchToProfile(this.profiles.get(uid));
     }.bind(this), false);
 
     wrap.className = "profile-name";
-    wrap.textContent = "Profile " + uid;
+    wrap.textContent = L10N.getFormatStr("profiler.profileName", [uid]);
 
     item.appendChild(wrap);
     list.appendChild(item);
 
     let profile = new ProfileUI(uid, this);
     this.profiles.set(uid, profile);
 
     this.emit("profileCreated", uid);
--- a/browser/devtools/profiler/cleopatra/cleopatra.html
+++ b/browser/devtools/profiler/cleopatra/cleopatra.html
@@ -7,16 +7,17 @@
   <head>
     <title>Firefox Profiler (SPS)</title>
     <meta charset="utf-8">
 
     <link rel="stylesheet" type="text/css" href="profiler/cleopatra/css/ui.css">
     <link rel="stylesheet" type="text/css" href="profiler/cleopatra/css/tree.css">
     <link rel="stylesheet" type="text/css" href="profiler/cleopatra/css/devtools.css">
 
+    <script src="profiler/cleopatra/js/strings.js"></script>
     <script src="profiler/cleopatra/js/parser.js"></script>
     <script src="profiler/cleopatra/js/tree.js"></script>
     <script src="profiler/cleopatra/js/ui.js"></script>
     <script src="profiler/cleopatra/js/ProgressReporter.js"></script>
     <script src="profiler/cleopatra/js/devtools.js"></script>
   </head>
 
   <body onload="notifyParent('loaded');">
--- a/browser/devtools/profiler/cleopatra/js/devtools.js
+++ b/browser/devtools/profiler/cleopatra/js/devtools.js
@@ -80,34 +80,39 @@ function initUI() {
 
   gMainArea = document.createElement("div");
   gMainArea.id = "mainarea";
 
   container.appendChild(gMainArea);
   document.body.appendChild(container);
 
   var startButton = document.createElement("button");
-  startButton.innerHTML = "Start";
+  startButton.innerHTML = gStrings.getStr("profiler.start");
   startButton.addEventListener("click", function (event) {
     event.target.setAttribute("disabled", true);
     notifyParent("start");
   }, false);
 
   var stopButton = document.createElement("button");
-  stopButton.innerHTML = "Stop";
+  stopButton.innerHTML = gStrings.getStr("profiler.stop");
   stopButton.addEventListener("click", function (event) {
     event.target.setAttribute("disabled", true);
     notifyParent("stop");
   }, false);
 
   var controlPane = document.createElement("div");
+  var startProfiling = gStrings.getFormatStr("profiler.startProfiling",
+    ["<span class='btn'></span>"]);
+  var stopProfiling = gStrings.getFormatStr("profiler.stopProfiling",
+    ["<span class='btn'></span>"]);
+
   controlPane.className = "controlPane";
   controlPane.innerHTML =
-    "<p id='startWrapper'>Click <span class='btn'></span> to start profiling.</p>" +
-    "<p id='stopWrapper'>Click <span class='btn'></span> to stop profiling.</p>";
+    "<p id='startWrapper'>" + startProfiling + "</p>" +
+    "<p id='stopWrapper'>" + stopProfiling + "</p>";
 
   controlPane.querySelector("#startWrapper > span.btn").appendChild(startButton);
   controlPane.querySelector("#stopWrapper > span.btn").appendChild(stopButton);
 
   gMainArea.appendChild(controlPane);
 }
 
 /**
@@ -148,19 +153,19 @@ function enterFinishedProfileUI() {
 
   var tree = document.createElement("div");
   tree.className = "treeContainer";
   tree.style.width = "100%";
   tree.style.height = "100%";
 
   gTreeManager = new ProfileTreeManager();
   gTreeManager.treeView.setColumns([
-    { name: "sampleCount", title: "Running time" },
-    { name: "selfSampleCount", title: "Self" },
-    { name: "resource", title: "" },
+    { name: "sampleCount", title: gStrings["Running Time"] },
+    { name: "selfSampleCount", title: gStrings["Self"] },
+    { name: "resource", title: "" }
   ]);
 
   currRow = pane.insertRow(rowIndex++);
   currRow.style.height = "100%";
 
   var cell = currRow.insertCell(0);
   cell.appendChild(tree);
   tree.appendChild(gTreeManager.getContainer());
new file mode 100644
--- /dev/null
+++ b/browser/devtools/profiler/cleopatra/js/strings.js
@@ -0,0 +1,23 @@
+const Cu = Components.utils;
+Cu.import("resource:///modules/devtools/ProfilerHelpers.jsm");
+
+/**
+ * Shortcuts for the L10N helper functions. Used in Cleopatra.
+ */
+var gStrings = {
+  // This strings are here so that Cleopatra code could use a simple object
+  // lookup. This makes it easier to merge upstream changes.
+  "Complete Profile": L10N.getStr("profiler.completeProfile"),
+  "Sample Range": L10N.getStr("profiler.sampleRange"),
+  "Running Time": L10N.getStr("profiler.runningTime"),
+  "Self": L10N.getStr("profiler.self"),
+  "Symbol Name": L10N.getStr("profiler.symbolName"),
+
+  getStr: function (name) {
+    return L10N.getStr(name);
+  },
+
+  getFormatStr: function (name, params) {
+    return L10N.getFormatStr(name, params);
+  }
+};
\ No newline at end of file
--- a/browser/devtools/profiler/cleopatra/js/ui.js
+++ b/browser/devtools/profiler/cleopatra/js/ui.js
@@ -148,20 +148,20 @@ FileList.prototype = {
 
 function treeObjSort(a, b) {
   return b.counter - a.counter;
 }
 
 function ProfileTreeManager() {
   this.treeView = new TreeView();
   this.treeView.setColumns([
-    { name: "sampleCount", title: "Running time" },
-    { name: "selfSampleCount", title: "Self" },
+    { name: "sampleCount", title: gStrings["Running Time"] },
+    { name: "selfSampleCount", title: gStrings["Self"] },
     { name: "resource", title: "" },
-    { name: "symbolName", title: "Symbol Name"}
+    { name: "symbolName", title: gStrings["Symbol Name"] }
   ]);
   var self = this;
   this.treeView.addEventListener("select", function (frameData) {
     self.highlightFrame(frameData);
     if (window.comparator_setSelection) {
       window.comparator_setSelection(gTreeManager.serializeCurrentSelectionSnapshot(), frameData);
     }
   });
@@ -747,17 +747,17 @@ RangeSelector.prototype = {
     if (this._transientRestrictionEnteringAffordance) {
       this._transientRestrictionEnteringAffordance.discard();
     }
   },
   _finishSelection: function RangeSelector__finishSelection(start, end) {
     var newFilterChain = gSampleFilters.concat({ type: "RangeSampleFilter", start: start, end: end });
     var self = this;
     self._transientRestrictionEnteringAffordance = gBreadcrumbTrail.add({
-      title: "Sample Range [" + start + ", " + (end + 1) + "]",
+      title: gStrings["Sample Range"] + " [" + start + ", " + (end + 1) + "]",
       enterCallback: function () {
         gSampleFilters = newFilterChain;
         self.collapseHistogramSelection();
         filtersChanged();
       }
     });
   },
   finishHistogramSelection: function RangeSelector_finishHistgramSelection(isSomethingSelected) {
@@ -1769,17 +1769,17 @@ function enterFinishedProfileUI() {
   //currRow = finishedProfilePane.insertRow(4);
   treeContainerDiv.appendChild(gPluginView.getContainer());
 
   gMainArea.appendChild(finishedProfilePaneBackgroundCover);
   gMainArea.appendChild(finishedProfilePane);
 
   var currentBreadcrumb = gSampleFilters;
   gBreadcrumbTrail.add({
-    title: "Complete Profile",
+    title: gStrings["Complete Profile"],
     enterCallback: function () {
       gSampleFilters = [];
       filtersChanged();
     }
   });
   if (currentBreadcrumb == null || currentBreadcrumb.length == 0) {
     gTreeManager.restoreSerializedSelectionSnapshot(gRestoreSelection);
     viewOptionsChanged();
--- a/browser/devtools/profiler/profiler.xul
+++ b/browser/devtools/profiler/profiler.xul
@@ -5,16 +5,21 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/global.css"?>
 <?xml-stylesheet href="chrome://browser/skin/devtools/common.css"?>
 <?xml-stylesheet href="chrome://browser/skin/devtools/splitview.css"?>
 <?xml-stylesheet href="chrome://browser/content/splitview.css"?>
 <?xml-stylesheet href="chrome://browser/content/profiler.css"?>
 
+<!DOCTYPE window [
+<!ENTITY % profilerDTD SYSTEM "chrome://browser/locale/devtools/profiler.dtd">
+  %profilerDTD;
+]>
+
 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <box flex="1" id="profiler-chrome" class="splitview-root">
     <box class="splitview-controller" width="180px">
       <box class="splitview-main"></box>
 
       <box class="splitview-nav-container">
         <ol class="splitview-nav" id="profiles-list">
           <!-- Example:
@@ -24,17 +29,17 @@
           -->
         </ol>
 
         <spacer flex="1"/>
 
         <toolbar class="devtools-toolbar" mode="full">
           <toolbarbutton id="profiler-create"
                          class="devtools-toolbarbutton"
-                         label="New"
+                         label="&profilerNew.label;"
                          disabled="true"/>
         </toolbar>
       </box> <!-- splitview-nav-container -->
     </box> <!-- splitview-controller -->
 
     <box flex="1">
       <vbox flex="1" id="profiler-report">
         <!-- Example:
new file mode 100644
--- /dev/null
+++ b/browser/locales/en-US/chrome/browser/devtools/profiler.dtd
@@ -0,0 +1,15 @@
+<!-- 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/. -->
+
+<!-- LOCALIZATION NOTE : FILE This file contains the Profiler strings -->
+
+<!-- LOCALIZATION NOTE : FILE The correct localization of this file might be to
+  - keep it in English, or another language commonly spoken among web developers.
+  - You want to make that choice consistent across the developer tools.
+  - A good criteria is the language in which you'd find the best
+  - documentation on web development on the web. -->
+
+<!-- LOCALIZATION NOTE (profilerNew.label): This is the label for the
+  -  button that creates a new profile. -->
+<!ENTITY profilerNew.label "New">
--- a/browser/locales/en-US/chrome/browser/devtools/profiler.properties
+++ b/browser/locales/en-US/chrome/browser/devtools/profiler.properties
@@ -14,8 +14,53 @@
 # This string is displayed in the title of the tab when the profiler is
 # displayed inside the developer tools window and in the Developer Tools Menu.
 profiler.label=Profiler
 
 # LOCALIZATION NOTE (profiler.tooltip):
 # This string is displayed in the tooltip of the tab when the profiler is
 # displayed inside the developer tools window.
 profiler.tooltip=Profiler
+
+# LOCALIZATION NOTE (profiler.profileName):
+# This string is the default name for new profiles. Its parameter is a number.
+# For example: "Profile 1", "Profile 2", etc.
+profiler.profileName=Profile %S
+
+# LOCALIZATION NOTE (profiler.completeProfile):
+# This string is displayed as a tab in the profiler UI. Clicking on it
+# displays everything that the profiler has generated so far.
+profiler.completeProfile=Complete Profile
+
+# LOCALIZATION NOTE (profiler.sampleRange):
+# This string is displayed as a tab in the profiler UI. Clicking on it
+# displays a sample range of data selected by user themselves.
+profiler.sampleRange=Sample Range
+
+# LOCALIZATION NOTE (profiler.runningTime):
+# This string is displayed as a table header in the profiler UI.
+profiler.runningTime=Running Time
+
+# LOCALIZATION NOTE (profiler.self):
+# This string is displayed as a table header in the profiler UI.
+profiler.self=Self
+
+# LOCALIZATION NOTE (profiler.symbolName)
+# This string is displayed as a table header in the profiler UI.
+profiler.symbolName=Symbol Name
+
+# LOCALIZATION NOTE (profiler.startProfiling)
+# This string is displayed around the button that starts the profiler.
+# String argument will be replaced with a Start button.
+profiler.startProfiling=Click here %S to start profiling
+
+# LOCALIZATION NOTE (profiler.stopProfiling)
+# This string is displayed around the button that stops the profiler.
+# String argument will be replaced with a Stop button.
+profiler.stopProfiling = Click here %S to stop profiling
+
+# LOCALIZATION NOTE (profiler.start)
+# This string is displayed on the button that starts the profiler.
+profiler.start=Start
+
+# LOCALIZATION NOTE (profiler.stop)
+# This string is displayed on the button that stops the profiler.
+profiler.stop=Stop
\ No newline at end of file
--- a/browser/locales/jar.mn
+++ b/browser/locales/jar.mn
@@ -33,16 +33,17 @@
     locale/browser/devtools/scratchpad.dtd            (%chrome/browser/devtools/scratchpad.dtd)
     locale/browser/devtools/styleeditor.properties    (%chrome/browser/devtools/styleeditor.properties)
     locale/browser/devtools/styleeditor.dtd           (%chrome/browser/devtools/styleeditor.dtd)
     locale/browser/devtools/styleinspector.properties (%chrome/browser/devtools/styleinspector.properties)
     locale/browser/devtools/styleinspector.dtd        (%chrome/browser/devtools/styleinspector.dtd)
     locale/browser/devtools/webConsole.dtd            (%chrome/browser/devtools/webConsole.dtd)
     locale/browser/devtools/sourceeditor.properties   (%chrome/browser/devtools/sourceeditor.properties)
     locale/browser/devtools/sourceeditor.dtd          (%chrome/browser/devtools/sourceeditor.dtd)
+    locale/browser/devtools/profiler.dtd              (%chrome/browser/devtools/profiler.dtd)
     locale/browser/devtools/profiler.properties       (%chrome/browser/devtools/profiler.properties)
     locale/browser/devtools/layoutview.dtd            (%chrome/browser/devtools/layoutview.dtd)
     locale/browser/devtools/responsiveUI.properties   (%chrome/browser/devtools/responsiveUI.properties)
     locale/browser/devtools/toolbox.dtd            (%chrome/browser/devtools/toolbox.dtd)
     locale/browser/devtools/toolbox.properties     (%chrome/browser/devtools/toolbox.properties)
     locale/browser/devtools/inspector.dtd          (%chrome/browser/devtools/inspector.dtd)
     locale/browser/devtools/connection-screen.dtd  (%chrome/browser/devtools/connection-screen.dtd)
     locale/browser/devtools/connection-screen.properties (%chrome/browser/devtools/connection-screen.properties)