mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-30 23:22:28 +01:00
Move some more strings to messages.properties and report (but don't throw) an error for unknown strings.
This commit is contained in:
@@ -11,7 +11,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("addons", {
|
||||
exports: ["AddonManager", "Addons", "Addon", "addons"],
|
||||
require: ["services"],
|
||||
use: ["completion", "config", "io", "prefs", "template", "util"]
|
||||
use: ["completion", "config", "io", "messages", "prefs", "template", "util"]
|
||||
}, this);
|
||||
|
||||
var callResult = function callResult(method) {
|
||||
@@ -49,7 +49,7 @@ var updateAddons = Class("UpgradeListener", AddonListener, {
|
||||
init.supercall(this, modules);
|
||||
|
||||
util.assert(!addons.length || addons[0].findUpdates,
|
||||
"Not available on " + config.host + " " + services.runtime.version);
|
||||
_("error.unavailible", config.host, services.runtime.version));
|
||||
|
||||
this.remaining = addons;
|
||||
this.upgrade = [];
|
||||
@@ -110,7 +110,7 @@ var actions = {
|
||||
name: "extr[ehash]",
|
||||
description: "Reload an extension",
|
||||
action: function (addon) {
|
||||
util.assert(util.haveGecko("2b"), "This command is not useful in this version of " + config.host);
|
||||
util.assert(util.haveGecko("2b"), _("error.notUseful", config.host));
|
||||
util.timeout(function () {
|
||||
addon.userDisabled = true;
|
||||
addon.userDisabled = false;
|
||||
@@ -413,17 +413,17 @@ var Addons = Module("addons", {
|
||||
function (args) {
|
||||
let name = args[0];
|
||||
if (args.bang && !command.bang)
|
||||
dactyl.assert(!name, "E488: Trailing characters");
|
||||
dactyl.assert(!name, _("error.trailing"));
|
||||
else
|
||||
dactyl.assert(name, "E471: Argument required");
|
||||
dactyl.assert(name, _("error.argumentRequired"));
|
||||
|
||||
AddonManager.getAddonsByTypes(["extension"], dactyl.wrapCallback(function (list) {
|
||||
if (!args.bang || command.bang) {
|
||||
list = list.filter(function (extension) extension.name == name);
|
||||
if (list.length == 0)
|
||||
return void dactyl.echoerr("E475: Invalid argument: " + name);
|
||||
return void dactyl.echoerr(_("error.invalidArgument", name));
|
||||
if (!list.every(ok))
|
||||
return void dactyl.echoerr("Permission denied");
|
||||
return void dactyl.echoerr(_("error.invalidOperation"));
|
||||
}
|
||||
if (command.actions)
|
||||
command.actions(list, this.modules);
|
||||
@@ -563,7 +563,7 @@ else
|
||||
});
|
||||
},
|
||||
getInstallForURL: function (url, callback, mimetype) {
|
||||
util.assert(false, "Install by URL not implemented");
|
||||
util.assert(false, _("error.unavailable", config.host, services.runtime.version));
|
||||
},
|
||||
observers: [],
|
||||
addAddonListener: function (listener) {
|
||||
|
||||
@@ -12,7 +12,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("commands", {
|
||||
exports: ["ArgType", "Command", "Commands", "CommandOption", "Ex", "commands"],
|
||||
require: ["contexts", "util"],
|
||||
use: ["config", "options", "services", "template"]
|
||||
use: ["config", "messages", "options", "services", "template"]
|
||||
}, this);
|
||||
|
||||
let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, ""));
|
||||
@@ -305,11 +305,11 @@ var Command = Class("Command", {
|
||||
if (this.command.argCount) {
|
||||
util.assert((this.length > 0 || !/^[1+]$/.test(this.command.argCount)) &&
|
||||
(this.literal == null || !/[1+]/.test(this.command.argCount) || /\S/.test(this.literalArg || "")),
|
||||
"E471: Argument required");
|
||||
_("error.argumentRequired"));
|
||||
|
||||
util.assert((this.length == 0 || this.command.argCount !== "0") &&
|
||||
(this.length <= 1 || !/^[01?]$/.test(this.command.argCount)),
|
||||
"E488: Trailing characters");
|
||||
_("error.trailing"));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -396,7 +396,7 @@ var Ex = Module("Ex", {
|
||||
let opt = cmd.optionMap["-" + k];
|
||||
let val = opt.type && opt.type.parse(v);
|
||||
util.assert(val != null && (typeof val !== "number" || !isNaN(val)),
|
||||
"No such option: " + k);
|
||||
_("option.noSuch", k));
|
||||
Class.replaceProperty(args, opt.names[0], val);
|
||||
args.explicitOpts[opt.names[0]] = val;
|
||||
}
|
||||
@@ -416,7 +416,7 @@ var Ex = Module("Ex", {
|
||||
_run: function E_run(name) {
|
||||
const self = this;
|
||||
let cmd = this.commands.get(name);
|
||||
util.assert(cmd, "No such command");
|
||||
util.assert(cmd, _("command.noSuch"));
|
||||
|
||||
return update(function exCommand(options) {
|
||||
let args = self._args(cmd, arguments);
|
||||
@@ -469,10 +469,10 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
||||
let name = names[0];
|
||||
|
||||
util.assert(!names.some(function (name) name in commands.builtin._map),
|
||||
"E182: Can't replace non-user command: " + name);
|
||||
_("command.cantReplace", name));
|
||||
|
||||
util.assert(replace || names.every(function (name) !(name in this._map), this),
|
||||
"Not replacing command " + name);
|
||||
_("command.wontReplace", name));
|
||||
|
||||
for (let name in values(names)) {
|
||||
ex.__defineGetter__(name, function () this._run(name));
|
||||
@@ -504,7 +504,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
||||
* @returns {Command}
|
||||
*/
|
||||
clear: function clear() {
|
||||
util.assert(this.group.modifiable, "Cannot delete non-user commands");
|
||||
util.assert(this.group.modifiable, _("command.cantDelete"));
|
||||
this._map = {};
|
||||
this._list = [];
|
||||
},
|
||||
@@ -529,7 +529,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
|
||||
* any of the command's names.
|
||||
*/
|
||||
remove: function remove(name) {
|
||||
util.assert(this.group.modifiable, "Cannot delete non-user commands");
|
||||
util.assert(this.group.modifiable, _("command.cantDelete"));
|
||||
|
||||
let cmd = this.get(name);
|
||||
this._list = this._list.filter(function (c) c !== cmd);
|
||||
@@ -586,7 +586,7 @@ var Commands = Module("commands", {
|
||||
return res.join("\n");
|
||||
res.push(lines[i]);
|
||||
}
|
||||
util.assert(false, "Unexpected end of file waiting for " + end);
|
||||
util.assert(false, _("command.eof", end));
|
||||
};
|
||||
|
||||
args = update({}, args || {});
|
||||
@@ -932,11 +932,12 @@ var Commands = Module("commands", {
|
||||
if (sub.indexOf(optname) == 0) {
|
||||
let count = 0;
|
||||
let invalid = false;
|
||||
let arg, uote, quoted;
|
||||
let arg, quote, quoted;
|
||||
|
||||
let sep = sub[optname.length];
|
||||
let argString = sub.substr(optname.length + 1);
|
||||
if (sep == "=" || /\s/.test(sep) && opt.type != CommandOption.NOARG) {
|
||||
[count, quoted, quote, error] = getNextArg(sub.substr(optname.length + 1), true);
|
||||
[count, quoted, quote, error] = getNextArg(argString, true);
|
||||
arg = Option.dequote(quoted);
|
||||
util.assert(!error, error);
|
||||
|
||||
@@ -951,7 +952,7 @@ var Commands = Module("commands", {
|
||||
|
||||
let context = null;
|
||||
if (!complete && quote)
|
||||
fail("Invalid argument for option " + optname);
|
||||
fail(_("command.invalidOptArg", optname, argString));
|
||||
|
||||
if (!invalid) {
|
||||
if (complete && !/[\s=]/.test(sep))
|
||||
@@ -975,7 +976,7 @@ var Commands = Module("commands", {
|
||||
|
||||
if (arg == null || (typeof arg == "number" && isNaN(arg))) {
|
||||
if (!complete || orig != "" || args.completeStart != str.length)
|
||||
fail("Invalid argument for " + opt.type.description + " option: " + optname);
|
||||
fail(_("command.invalidOptTypeArg", opt.type.description, optname, argString));
|
||||
if (complete)
|
||||
complete.highlight(args.completeStart, count - 1, "SPELLCHECK");
|
||||
}
|
||||
@@ -984,7 +985,7 @@ var Commands = Module("commands", {
|
||||
// we have a validator function
|
||||
if (typeof opt.validator == "function") {
|
||||
if (opt.validator(arg, quoted) == false && (arg || !complete)) {
|
||||
fail("Invalid argument for option: " + optname);
|
||||
fail(_("command.invalidOptArg", optname, argString));
|
||||
if (complete) // Always true.
|
||||
complete.highlight(args.completeStart, count - 1, "SPELLCHECK");
|
||||
}
|
||||
@@ -1046,9 +1047,9 @@ var Commands = Module("commands", {
|
||||
args.completeFilter = arg || "";
|
||||
}
|
||||
else if (count == -1)
|
||||
fail("Error parsing arguments: " + arg);
|
||||
fail(_("command.parsing", arg));
|
||||
else if (!onlyArgumentsRemaining && sub[0] === "-")
|
||||
fail("Invalid option: " + arg);
|
||||
fail(_("command.invalidOpt", arg));
|
||||
|
||||
if (arg != null)
|
||||
args.push(arg);
|
||||
@@ -1367,13 +1368,13 @@ var Commands = Module("commands", {
|
||||
let cmd = args[0];
|
||||
|
||||
util.assert(!cmd || cmd.split(",").every(commands.validName.closure.test),
|
||||
"E182: Invalid command name");
|
||||
_("command.invalidName", cmd));
|
||||
|
||||
if (!args.literalArg)
|
||||
commands.list();
|
||||
else {
|
||||
util.assert(args["-group"].modifiable,
|
||||
"Cannot change commands in the builtin group");
|
||||
_("group.cantChangeBuiltin", _("command.commands")));
|
||||
|
||||
let completer = args["-complete"];
|
||||
let completerFunc = null; // default to no completion for user commands
|
||||
@@ -1514,7 +1515,7 @@ var Commands = Module("commands", {
|
||||
commands.add(["delc[ommand]"],
|
||||
"Delete the specified user-defined command",
|
||||
function (args) {
|
||||
util.assert(args.bang ^ !!args[0], "Argument or ! required");
|
||||
util.assert(args.bang ^ !!args[0], _("error.argumentOrBang"));
|
||||
let name = args[0];
|
||||
|
||||
if (args.bang)
|
||||
@@ -1522,7 +1523,7 @@ var Commands = Module("commands", {
|
||||
else if (args["-group"].get(name))
|
||||
args["-group"].remove(name);
|
||||
else
|
||||
dactyl.echoerr("E184: No such user-defined command: " + name);
|
||||
dactyl.echoerr(_("command.noSuchUser", name));
|
||||
}, {
|
||||
argCount: "?",
|
||||
bang: true,
|
||||
|
||||
@@ -9,7 +9,7 @@ try {
|
||||
Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("contexts", {
|
||||
exports: ["Contexts", "Group", "contexts"],
|
||||
use: ["commands", "options", "services", "storage", "styles", "template", "util"]
|
||||
use: ["commands", "messages", "options", "services", "storage", "styles", "template", "util"]
|
||||
}, this);
|
||||
|
||||
var Const = function Const(val) Class.Property({ enumerable: true, value: val });
|
||||
@@ -324,7 +324,7 @@ var Contexts = Module("contexts", {
|
||||
|
||||
let group = this.getGroup(name);
|
||||
|
||||
util.assert(!group || !group.builtin, "Cannot remove builtin group");
|
||||
util.assert(!group || !group.builtin, _("group.cantRemoveBuiltin"));
|
||||
|
||||
if (group) {
|
||||
name = group.name;
|
||||
@@ -445,8 +445,8 @@ var Contexts = Module("contexts", {
|
||||
function (args) {
|
||||
if (args.length > 0) {
|
||||
var name = Option.dequote(args[0]);
|
||||
util.assert(name !== "builtin", "Cannot modify builtin group");
|
||||
util.assert(commands.validName.test(name), "Invalid group name");
|
||||
util.assert(name !== "builtin", _("group.cantModifyBuiltin"));
|
||||
util.assert(commands.validName.test(name), _("group.invalidName", name));
|
||||
|
||||
var group = contexts.getGroup(name);
|
||||
}
|
||||
@@ -455,7 +455,7 @@ var Contexts = Module("contexts", {
|
||||
else
|
||||
return void modules.completion.listCompleter("group", "", null, null);
|
||||
|
||||
util.assert(group || name, "No current group");
|
||||
util.assert(group || name, _("group.noCurrent"));
|
||||
|
||||
let filter = Group.compileFilter(args["-locations"]);
|
||||
if (!group || args.bang)
|
||||
@@ -481,7 +481,7 @@ var Contexts = Module("contexts", {
|
||||
util.assert(!group.builtin ||
|
||||
!["-description", "-locations", "-nopersist"]
|
||||
.some(function (arg) set.has(args.explicitOpts, arg)),
|
||||
"Cannot modify builtin group");
|
||||
_("group.cantModifyBuiltin"));
|
||||
},
|
||||
{
|
||||
argCount: "?",
|
||||
@@ -538,7 +538,7 @@ var Contexts = Module("contexts", {
|
||||
commands.add(["delg[roup]"],
|
||||
"Delete a group",
|
||||
function (args) {
|
||||
util.assert(contexts.getGroup(args[0]), "No such group: " + args[0]);
|
||||
util.assert(contexts.getGroup(args[0]), _("group.noSuch", args[0]));
|
||||
contexts.removeGroup(args[0]);
|
||||
},
|
||||
{
|
||||
@@ -552,7 +552,7 @@ var Contexts = Module("contexts", {
|
||||
commands.add(["fini[sh]"],
|
||||
"Stop sourcing a script file",
|
||||
function (args) {
|
||||
util.assert(args.context, "E168: :finish used outside of a sourced file");
|
||||
util.assert(args.context, _("command.finish.illegal"));
|
||||
args.context.finished = true;
|
||||
},
|
||||
{ argCount: "0" });
|
||||
@@ -560,14 +560,14 @@ var Contexts = Module("contexts", {
|
||||
function checkStack(cmd) {
|
||||
util.assert(contexts.context && contexts.context.stack &&
|
||||
contexts.context.stack[cmd] && contexts.context.stack[cmd].length,
|
||||
"Invalid use of conditional");
|
||||
_("command.conditional.illegal"));
|
||||
}
|
||||
function pop(cmd) {
|
||||
checkStack(cmd);
|
||||
return contexts.context.stack[cmd].pop();
|
||||
}
|
||||
function push(cmd, value) {
|
||||
util.assert(contexts.context, "Invalid use of conditional");
|
||||
util.assert(contexts.context, _("command.conditional.illegal"));
|
||||
if (arguments.length < 2)
|
||||
value = contexts.context.noExecute;
|
||||
contexts.context.stack = contexts.context.stack || {};
|
||||
|
||||
@@ -8,7 +8,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("highlight", {
|
||||
exports: ["Highlight", "Highlights", "highlight"],
|
||||
require: ["services", "styles", "util"],
|
||||
use: ["template"]
|
||||
use: ["messages", "template"]
|
||||
}, this);
|
||||
|
||||
var Highlight = Struct("class", "selector", "sites",
|
||||
@@ -306,7 +306,7 @@ var Highlights = Module("Highlight", {
|
||||
highlight.clear();
|
||||
else {
|
||||
lastScheme = modules.io.sourceFromRuntimePath(["colors/" + scheme + "." + config.fileExtension]);
|
||||
dactyl.assert(lastScheme, "E185: Cannot find color scheme " + scheme);
|
||||
dactyl.assert(lastScheme, _("command.colorscheme.notFound", scheme));
|
||||
}
|
||||
autocommands.trigger("ColorScheme", { name: scheme });
|
||||
},
|
||||
@@ -337,7 +337,7 @@ var Highlights = Module("Highlight", {
|
||||
if (!modify && /&$/.test(key))
|
||||
[clear, modify, key] = [true, true, key.replace(/&$/, "")];
|
||||
|
||||
dactyl.assert(!(clear && css), "E488: Trailing characters");
|
||||
dactyl.assert(!(clear && css), _("error.trailing"));
|
||||
|
||||
if (!modify)
|
||||
modules.commandline.commandOutput(
|
||||
@@ -355,7 +355,7 @@ var Highlights = Module("Highlight", {
|
||||
else if (key)
|
||||
highlight.set(key, css, clear, "-append" in args, args["-link"]);
|
||||
else
|
||||
util.assert(false, "Invalid arguments");
|
||||
util.assert(false, _("error.invalidArgument"));
|
||||
},
|
||||
{
|
||||
// TODO: add this as a standard highlight completion function?
|
||||
|
||||
@@ -13,7 +13,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("io", {
|
||||
exports: ["IO", "io"],
|
||||
require: ["services"],
|
||||
use: ["config", "storage", "styles", "template", "util"]
|
||||
use: ["config", "messages", "storage", "styles", "template", "util"]
|
||||
}, this);
|
||||
|
||||
// TODO: why are we passing around strings rather than file objects?
|
||||
@@ -251,12 +251,12 @@ var IO = Module("io", {
|
||||
newDir = newDir && newDir.path || newDir || "~";
|
||||
|
||||
if (newDir == "-") {
|
||||
util.assert(this._oldcwd != null, "E186: No previous directory");
|
||||
util.assert(this._oldcwd != null, _("io.noPrevDir"));
|
||||
[this._cwd, this._oldcwd] = [this._oldcwd, this.cwd];
|
||||
}
|
||||
else {
|
||||
let dir = io.File(newDir);
|
||||
util.assert(dir.exists() && dir.isDirectory(), "E344: Can't find directory " + dir.path.quote());
|
||||
util.assert(dir.exists() && dir.isDirectory(), _("io.noSuchDir", dir.path.quote()));
|
||||
dir.normalize();
|
||||
[this._cwd, this._oldcwd] = [dir.path, this.cwd];
|
||||
}
|
||||
@@ -483,7 +483,7 @@ var IO = Module("io", {
|
||||
|
||||
let shell = io.pathSearch(storage["options"].get("shell").value);
|
||||
let shcf = storage["options"].get("shellcmdflag").value;
|
||||
util.assert(shell, "Invalid 'shell'");
|
||||
util.assert(shell, _("error.invalid", "'shell'"));
|
||||
|
||||
if (isArray(command))
|
||||
command = command.map(escape).join(" ");
|
||||
|
||||
@@ -20,11 +20,19 @@ var Messages = Module("messages", {
|
||||
|
||||
this.bundle = services.stringBundle.createBundle(JSMLoader.getTarget("dactyl://locale/messages.properties"));
|
||||
|
||||
this._ = function _(message) {
|
||||
if (arguments.length > 1) {
|
||||
let args = Array.slice(arguments, 1);
|
||||
return this.format(message + "-" + args.length, args, null) || this.format(message, args);
|
||||
}
|
||||
return this.get(message);
|
||||
};
|
||||
|
||||
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] = {
|
||||
this._[key] = this[key] = {
|
||||
__noSuchMethod__: function __(prop, args) self._.apply(self, [prop].concat(args))
|
||||
};
|
||||
}
|
||||
@@ -34,19 +42,14 @@ var Messages = Module("messages", {
|
||||
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) {
|
||||
// Report error so tests fail, but don't throw
|
||||
if (arguments.length < 2)
|
||||
util.reportError(Error("Invalid locale string: " + value + ": " + e));
|
||||
return arguments.length > 1 ? default_ : value;
|
||||
}
|
||||
},
|
||||
@@ -56,6 +59,9 @@ var Messages = Module("messages", {
|
||||
return this.bundle.formatStringFromName(value, args, args.length);
|
||||
}
|
||||
catch (e) {
|
||||
// Report error so tests fail, but don't throw
|
||||
if (arguments.length < 3)
|
||||
util.reportError(Error("Invalid locale string: " + value + ": " + e));
|
||||
return arguments.length > 2 ? default_ : value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||
defineModule("template", {
|
||||
exports: ["Binding", "Template", "template"],
|
||||
require: ["util"],
|
||||
use: ["services"]
|
||||
use: ["messages", "services"]
|
||||
}, this);
|
||||
|
||||
default xml namespace = XHTML;
|
||||
|
||||
Reference in New Issue
Block a user