Skip to content

Commit

Permalink
FBTrace: localization fixed (issue 6235)
Browse files Browse the repository at this point in the history
  • Loading branch information
janodvarko committed Feb 8, 2013
1 parent 3a73c72 commit 3d42244
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 27 deletions.
1 change: 0 additions & 1 deletion trace/FBTrace/chrome/content/lib/css.js
Expand Up @@ -92,7 +92,6 @@ Css.removeClass = function(node, name)
re = new RegExp('(^|\\s)' + name + '(\\s|$)', "g");

node.className = node.className.replace(re, " ");

};

Css.toggleClass = function(elt, name)
Expand Down
46 changes: 44 additions & 2 deletions trace/FBTrace/chrome/content/lib/locale.js
@@ -1,6 +1,22 @@
/* See license.txt for terms of usage */

define([], function() {
define([
"fbtrace/trace"
],
function(FBTrace) {

// ********************************************************************************************* //
// Constants

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;

Cu["import"]("resource://gre/modules/Services.jsm");

var stringBundleService = Services.strings;

var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);

// ********************************************************************************************* //
// Module
Expand All @@ -13,7 +29,6 @@ Locale.$STR = function(name, bundle)

try
{
// The en-US string should be always available.
var defaultBundle = Locale.getDefaultStringBundle();
if (defaultBundle)
return defaultBundle.GetStringFromName(strKey);
Expand All @@ -39,6 +54,33 @@ Locale.getDefaultStringBundle = function()
return this.defaultStringBundle;
};

Locale.registerStringBundle = function(bundleURI)
{
// Notice that this category entry must not be persistent in Fx 4.0
categoryManager.addCategoryEntry("strings_fbtrace", bundleURI, "", false, true);
this.defaultStringBundle = null;
};

Locale.internationalize = function(element, attr)
{
if (element)
{
var xulString = element.getAttribute(attr);
if (xulString)
{
var localized = Locale.$STR(xulString);
// Set localized value of the attribute only if it exists.
if (localized)
element.setAttribute(attr, localized);
}
}
else
{
if (FBTrace.DBG_LOCALE)
FBTrace.sysout("Failed to internationalize element with attr "+attr+" args:"+args);
}
};

// ********************************************************************************************* //

return Locale;
Expand Down
17 changes: 9 additions & 8 deletions trace/FBTrace/chrome/content/messageTemplate.js
Expand Up @@ -704,15 +704,16 @@ var MessageTemplate = domplate(Reps.Rep,
this.updateInfoImpl(messageInfoBody, view, message, message.getProperties,
function (message, valueBox, text) {
var win = messageInfoBody.ownerDocument.defaultView;
if (message.obj instanceof win.Element.constructor)
{
Firebug.HTMLPanel.CompleteElement.tag.replace({object: message.obj}, valueBox,
Firebug.HTMLPanel.CompleteElement);
}
else
{
// xxxHonza: HTML Reps must be ported.
//if (message.obj instanceof win.Element.constructor)
//{
// HTMLPanel.CompleteElement.tag.replace({object: message.obj}, valueBox,
// HTMLPanel.CompleteElement);
//}
//else
//{
PropertyTree.tag.replace({object: message.obj}, valueBox, PropertyTree);
}
//}
});
}
else if (Css.hasClass(tab, "messageInfoExcTab"))
Expand Down
43 changes: 33 additions & 10 deletions trace/FBTrace/chrome/content/traceConsole.js
Expand Up @@ -7,15 +7,16 @@ define([
"fbtrace/lib/css",
"fbtrace/lib/dom",
"fbtrace/lib/options",
"fbtrace/lib/array",
"fbtrace/serializer",
"fbtrace/traceObjectInspector",
"fbtrace/traceMessage",
"fbtrace/messageTemplate",
"fbtrace/commonBaseUI",
"fbtrace/traceCommandLine",
],
function(FBTrace, Locale, Obj, Css, Dom, Options, Serializer, TraceObjectInspector, TraceMessage,
MessageTemplate, CommonBaseUI, TraceCommandLine) {
function(FBTrace, Locale, Obj, Css, Dom, Options, Arr, Serializer, TraceObjectInspector,
TraceMessage, MessageTemplate, CommonBaseUI, TraceCommandLine) {

// ********************************************************************************************* //
// Constants
Expand Down Expand Up @@ -46,6 +47,8 @@ var scope = {};
Cu["import"]("resource://fbtrace/firebug-trace-service.js", scope);
var traceService = scope.traceConsoleService;

Locale.registerStringBundle("chrome://fbtrace/locale/firebug-tracing.properties");

// ********************************************************************************************* //
// Trace Window Implementation

Expand Down Expand Up @@ -76,7 +79,7 @@ var TraceConsole =
catch (exc)
{
var msg = exc.toString() +" "+(exc.fileName || exc.sourceName) + "@" + exc.lineNumber;
window.dump("FBTrace; Firebug.TraceModule.initialize EXCEPTION " + msg);
window.dump("FBTrace; TraceModule.initialize EXCEPTION " + msg);
}
},

Expand All @@ -96,13 +99,7 @@ var TraceConsole =
};

// Make sure the UI is localized.
Firebug.internationalizeUI(window.document);

if (!Firebug.TraceModule)
{
window.dump("FBTrace; TraceModule == NULL\n");
return;
}
this.internationalizeUI(window.document);

this.consoleNode = consoleFrame.contentDocument.getElementById("panelNode-traceConsole");

Expand Down Expand Up @@ -178,6 +175,32 @@ var TraceConsole =
window.close();
},

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Localization

/**
* Substitute strings in the UI, with fall back to en-US
*/
internationalizeUI: function(doc)
{
if (!doc)
return;

var elements = doc.getElementsByClassName("fbInternational");
elements = Arr.cloneArray(elements);
var attributes = ["label", "tooltiptext", "aria-label"];
for (var i=0; i<elements.length; i++)
{
var element = elements[i];
Css.removeClass(elements[i], "fbInternational");
for (var j=0; j<attributes.length; j++)
{
if (element.hasAttribute(attributes[j]))
Locale.internationalize(element, attributes[j]);
}
}
},

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Asynchronous display

Expand Down
1 change: 0 additions & 1 deletion trace/FBTrace/chrome/content/traceConsole.xul
Expand Up @@ -34,7 +34,6 @@

<!-- String Bundles -->
<stringbundle id="bundle_findBar" src="chrome://global/locale/findbar.properties"/>
<stringbundle id="strings_fbtrace" src="chrome://fbtrace/locale/firebug-tracing.properties"/>

<commandset id="mainCommandSet">
<command id="cmd_clearConsole" oncommand="TraceConsole.onClearConsole()"/>
Expand Down
2 changes: 2 additions & 0 deletions trace/FBTrace/chrome/content/traceMessage.js
Expand Up @@ -17,6 +17,8 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;

var EOF = "<br/>";

// ********************************************************************************************* //
// Trace Message Object

Expand Down
5 changes: 0 additions & 5 deletions trace/FBTrace/chrome/content/traceModule.js
Expand Up @@ -20,11 +20,6 @@ var Cu = Components.utils;

var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);

var EOF = "<br/>";

// Register locale file with strings for the Tracing Console window.
Firebug.registerStringBundle("chrome://fbtrace/locale/firebug-tracing.properties");

// ********************************************************************************************* //
// Trace Module

Expand Down

0 comments on commit 3d42244

Please sign in to comment.