1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-14 05:25:48 +01:00

Allow localization of command/mapping/option descriptions.

This commit is contained in:
Kris Maglione
2011-03-04 20:37:29 -05:00
parent f3c14e861c
commit 058094f87d
8 changed files with 139 additions and 78 deletions

View File

@@ -78,6 +78,48 @@ var Messages = Module("messages", {
}
}, {
Localized: Class("Localized", Class.Property, {
init: function init(prop, obj) {
let _prop = "localized_" + prop;
if (this.initialized) {
/*
if (config.locale === "en-US")
return { configurable: true, enumerable: true, value: null, writable: true };
*/
obj[_prop] = this.default;
return {
get: function get() {
let self = this;
let value = this[_prop];
function getter(key, default_) function getter() messages.get([name, key].join("."), default_);
let name = [this.constructor.className.toLowerCase(), this.identifier || this.name, prop].join(".");
if (!isObject(value))
value = messages.get(name, value)
else if (isArray(value))
// Deprecated
iter(value).forEach(function ([k, v]) {
if (isArray(v))
memoize(v, 1, getter(v[0], v[1]));
else
memoize(value, k, getter(k, v));
});
else
iter(value).forEach(function ([k, v]) {
memoize(value, k, function () messages.get([name, k].join("."), v));
});
return Class.replaceProperty(this, prop, value);
},
set: function set(val) this[_prop] = val
}
}
this.default = prop;
this.initialized = true;
}
})
}, {
javascript: function initJavascript(dactyl, modules, window) {
modules.JavaScript.setCompleter([this._, this.get, this.format], [