mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-11 12:15:46 +01:00
Move some messages to properties file. Local and modules directories still to be done.
This commit is contained in:
73
common/modules/messages.jsm
Normal file
73
common/modules/messages.jsm
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2011 by Kris Maglione <maglione.k@gmail.com>
|
||||
//
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
"use strict";
|
||||
|
||||
try {
|
||||
|
||||
Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("messages", {
|
||||
exports: ["Messages", "messages", "_"],
|
||||
require: ["services", "util"]
|
||||
}, this);
|
||||
|
||||
// TODO: Lazy instantiation
|
||||
var Messages = Module("messages", {
|
||||
|
||||
init: function init() {
|
||||
let self = this;
|
||||
|
||||
this.bundle = services.stringBundle.createBundle(JSMLoader.getTarget("dactyl://locale/messages.properties"));
|
||||
|
||||
let seen = {};
|
||||
for (let prop in iter(this.bundle.getSimpleEnumeration())) {
|
||||
let key = prop.QueryInterface(Ci.nsIPropertyElement).key.split(".")[0];
|
||||
if (!set.add(seen, key))
|
||||
this[key] = {
|
||||
__noSuchMethod__: function __(prop, args) self._.apply(self, [prop].concat(args))
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
cleanup: function cleanup() {
|
||||
services.stringBundle.flushBundles();
|
||||
},
|
||||
|
||||
_: function _(message) {
|
||||
if (arguments.length > 1) {
|
||||
let args = Array.slice(arguments, 1);
|
||||
return this.format(message + "-", args, null) || this.format(message, args);
|
||||
}
|
||||
return this.get(message);
|
||||
},
|
||||
|
||||
get: function get(value, default_) {
|
||||
try {
|
||||
return this.bundle.GetStringFromName(value);
|
||||
}
|
||||
catch (e) {
|
||||
return arguments.length > 1 ? default_ : value;
|
||||
}
|
||||
},
|
||||
|
||||
format: function format(value, args, default_) {
|
||||
try {
|
||||
return this.bundle.formatStringFromName(value, args, args.length);
|
||||
}
|
||||
catch (e) {
|
||||
return arguments.length > 2 ? default_ : value;
|
||||
}
|
||||
}
|
||||
|
||||
}, {
|
||||
}, {
|
||||
});
|
||||
|
||||
var { _ } = messages.closure;
|
||||
|
||||
endModule();
|
||||
|
||||
} catch(e){ if (!e.stack) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); }
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et ft=javascript:
|
||||
@@ -163,6 +163,7 @@ var Overlay = Module("Overlay", {
|
||||
"highlight",
|
||||
"io",
|
||||
"javascript",
|
||||
"messages",
|
||||
"options",
|
||||
"overlay",
|
||||
"prefs",
|
||||
|
||||
Reference in New Issue
Block a user