mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add i18n function to editor plugins when they are registered
Adds a `_` function to the plugin definition object that will automatically prepend the plugin's module namespace to any call. This saves the plugin from having to prepend its namespace all of the time.
This commit is contained in:
parent
9f71dbb006
commit
9e179170ee
@ -8,6 +8,23 @@ RED.plugins = (function() {
|
|||||||
pluginsByType[definition.type] = pluginsByType[definition.type] || [];
|
pluginsByType[definition.type] = pluginsByType[definition.type] || [];
|
||||||
pluginsByType[definition.type].push(definition);
|
pluginsByType[definition.type].push(definition);
|
||||||
}
|
}
|
||||||
|
if (RED._loadingModule) {
|
||||||
|
definition.module = RED._loadingModule;
|
||||||
|
definition["_"] = function() {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
var originalKey = args[0];
|
||||||
|
if (!/:/.test(args[0])) {
|
||||||
|
args[0] = definition.module+":"+args[0];
|
||||||
|
}
|
||||||
|
var result = RED._.apply(null,args);
|
||||||
|
if (result === args[0]) {
|
||||||
|
return originalKey;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
definition["_"] = RED["_"]
|
||||||
|
}
|
||||||
if (definition.onadd && typeof definition.onadd === 'function') {
|
if (definition.onadd && typeof definition.onadd === 'function') {
|
||||||
definition.onadd();
|
definition.onadd();
|
||||||
}
|
}
|
||||||
|
@ -67,11 +67,11 @@ var RED = (function() {
|
|||||||
var moduleId;
|
var moduleId;
|
||||||
if (moduleIdMatch) {
|
if (moduleIdMatch) {
|
||||||
moduleId = moduleIdMatch[1];
|
moduleId = moduleIdMatch[1];
|
||||||
|
RED._loadingModule = moduleId;
|
||||||
} else {
|
} else {
|
||||||
moduleId = "unknown";
|
moduleId = "unknown";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var hasDeferred = false;
|
var hasDeferred = false;
|
||||||
var nodeConfigEls = $("<div>"+config+"</div>");
|
var nodeConfigEls = $("<div>"+config+"</div>");
|
||||||
var scripts = nodeConfigEls.find("script");
|
var scripts = nodeConfigEls.find("script");
|
||||||
@ -85,6 +85,7 @@ var RED = (function() {
|
|||||||
scriptCount--;
|
scriptCount--;
|
||||||
if (scriptCount === 0) {
|
if (scriptCount === 0) {
|
||||||
$(targetContainer).append(nodeConfigEls);
|
$(targetContainer).append(nodeConfigEls);
|
||||||
|
delete RED._loadingModule;
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,6 +109,7 @@ var RED = (function() {
|
|||||||
})
|
})
|
||||||
if (!hasDeferred) {
|
if (!hasDeferred) {
|
||||||
$(targetContainer).append(nodeConfigEls);
|
$(targetContainer).append(nodeConfigEls);
|
||||||
|
delete RED._loadingModule;
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@ -116,6 +118,7 @@ var RED = (function() {
|
|||||||
timeout: 10000
|
timeout: 10000
|
||||||
});
|
});
|
||||||
console.log("["+moduleId+"] "+err.toString());
|
console.log("["+moduleId+"] "+err.toString());
|
||||||
|
delete RED._loadingModule;
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user