EXPORTED_SYMBOLS = ["module"];
var module = function (application) {
var log = function (message) {
application.logger.trace("[Simple String Templates] " + message);
}
;
var SimpleStringTemplates = function (fileName) {
this.fileName = fileName;
this._templates = {
};
}
;
SimpleStringTemplates.prototype = {
constructor: SimpleStringTemplates,
__stringBundle: null,
get _stringBundle() {
return this.__stringBundle ? this.__stringBundle : (this.__stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService).createBundle(application.api.Package.resolvePath(this.fileName)));
}
,
getString: function (key, data) {
var template = this._getTemplateString(key);
return this._applyTemplate(template,data);
}
,
_getTemplateString: function (key) {
var stringBundle = this._stringBundle;
if ("undefined" == typeof this._templates[key])
{
this._templates[key] = stringBundle.GetStringFromName(key);
}

return this._templates[key];
}
,
_applyTemplate: function (template, data) {
log("template: \"" + template + "\".");
log("data: \"" + (data ? JSON.stringify(data) : "none") + "\".");
var result = template;
if ("undefined" != typeof data && template.indexOf("{{") != - 1)
{
for(var item in data) {
if (data.hasOwnProperty(item))
{
let pattern = "{{" + item + "}}";
let replacement = String(data[item]);
result = result.replace(pattern,replacement,"g");
}

}

}

log("result: \"" + result + "\".");
return result;
}
};
return SimpleStringTemplates;
}
;
