mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add RED.actions.getLabel to retrieve action i18n label
This commit is contained in:
parent
22879f8c23
commit
ea46947054
@ -21,28 +21,12 @@ RED.actions = (function() {
|
|||||||
function getAction(name) {
|
function getAction(name) {
|
||||||
return actions[name].handler;
|
return actions[name].handler;
|
||||||
}
|
}
|
||||||
function invokeAction() {
|
function getActionLabel(name) {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
let def = actions[name]
|
||||||
var name = args.shift();
|
if (!def) {
|
||||||
if (actions.hasOwnProperty(name)) {
|
return ''
|
||||||
var handler = actions[name].handler;
|
|
||||||
handler.apply(null, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function listActions() {
|
|
||||||
var result = [];
|
|
||||||
var missing = [];
|
|
||||||
Object.keys(actions).forEach(function(action) {
|
|
||||||
var def = actions[action];
|
|
||||||
var shortcut = RED.keyboard.getShortcut(action);
|
|
||||||
var isUser = false;
|
|
||||||
if (shortcut) {
|
|
||||||
isUser = shortcut.user;
|
|
||||||
} else {
|
|
||||||
isUser = !!RED.keyboard.getUserShortcut(action);
|
|
||||||
}
|
}
|
||||||
if (!def.label) {
|
if (!def.label) {
|
||||||
var name = action;
|
|
||||||
var options = def.options;
|
var options = def.options;
|
||||||
var key = options ? options.label : undefined;
|
var key = options ? options.label : undefined;
|
||||||
if (!key) {
|
if (!key) {
|
||||||
@ -58,12 +42,36 @@ RED.actions = (function() {
|
|||||||
return " "+arguments[4].toUpperCase();
|
return " "+arguments[4].toUpperCase();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
missing.push(key);
|
|
||||||
}
|
}
|
||||||
def.label = label;
|
def.label = label;
|
||||||
}
|
}
|
||||||
//console.log("; missing:", missing);
|
return def.label
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function invokeAction() {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
var name = args.shift();
|
||||||
|
if (actions.hasOwnProperty(name)) {
|
||||||
|
var handler = actions[name].handler;
|
||||||
|
handler.apply(null, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function listActions() {
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
Object.keys(actions).forEach(function(action) {
|
||||||
|
var def = actions[action];
|
||||||
|
var shortcut = RED.keyboard.getShortcut(action);
|
||||||
|
var isUser = false;
|
||||||
|
if (shortcut) {
|
||||||
|
isUser = shortcut.user;
|
||||||
|
} else {
|
||||||
|
isUser = !!RED.keyboard.getUserShortcut(action);
|
||||||
|
}
|
||||||
|
if (!def.label) {
|
||||||
|
def.label = getActionLabel(action)
|
||||||
|
}
|
||||||
result.push({
|
result.push({
|
||||||
id:action,
|
id:action,
|
||||||
scope:shortcut?shortcut.scope:undefined,
|
scope:shortcut?shortcut.scope:undefined,
|
||||||
@ -79,6 +87,7 @@ RED.actions = (function() {
|
|||||||
add: addAction,
|
add: addAction,
|
||||||
remove: removeAction,
|
remove: removeAction,
|
||||||
get: getAction,
|
get: getAction,
|
||||||
|
getLabel: getActionLabel,
|
||||||
invoke: invokeAction,
|
invoke: invokeAction,
|
||||||
list: listActions
|
list: listActions
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user