mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Add RED.actions.getLabel to retrieve action i18n label
This commit is contained in:
		@@ -21,6 +21,34 @@ RED.actions = (function() {
 | 
			
		||||
    function getAction(name) {
 | 
			
		||||
        return actions[name].handler;
 | 
			
		||||
    }
 | 
			
		||||
    function getActionLabel(name) {
 | 
			
		||||
        let def = actions[name]
 | 
			
		||||
        if (!def) {
 | 
			
		||||
            return ''
 | 
			
		||||
        }
 | 
			
		||||
        if (!def.label) {
 | 
			
		||||
            var options = def.options;
 | 
			
		||||
            var key = options ? options.label : undefined;
 | 
			
		||||
            if (!key) {
 | 
			
		||||
                key = "action-list." +name.replace(/^.*:/,"");
 | 
			
		||||
            }
 | 
			
		||||
            var label = RED._(key);
 | 
			
		||||
            if (label === key) {
 | 
			
		||||
                // no translation. convert `name` to description
 | 
			
		||||
                label = name.replace(/(^.+:([a-z]))|(-([a-z]))/g, function() {
 | 
			
		||||
                    if (arguments[5] === 0) {
 | 
			
		||||
                        return arguments[2].toUpperCase();
 | 
			
		||||
                    } else {
 | 
			
		||||
                        return " "+arguments[4].toUpperCase();
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
            def.label = label;
 | 
			
		||||
        }
 | 
			
		||||
        return def.label
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    function invokeAction() {
 | 
			
		||||
        var args = Array.prototype.slice.call(arguments);
 | 
			
		||||
        var name = args.shift();
 | 
			
		||||
@@ -31,7 +59,7 @@ RED.actions = (function() {
 | 
			
		||||
    }
 | 
			
		||||
    function listActions() {
 | 
			
		||||
        var result = [];
 | 
			
		||||
        var missing = [];
 | 
			
		||||
 | 
			
		||||
        Object.keys(actions).forEach(function(action) {
 | 
			
		||||
            var def = actions[action];
 | 
			
		||||
            var shortcut = RED.keyboard.getShortcut(action);
 | 
			
		||||
@@ -42,28 +70,8 @@ RED.actions = (function() {
 | 
			
		||||
                isUser = !!RED.keyboard.getUserShortcut(action);
 | 
			
		||||
            }
 | 
			
		||||
            if (!def.label) {
 | 
			
		||||
                var name = action;
 | 
			
		||||
                var options = def.options;
 | 
			
		||||
                var key = options ? options.label : undefined;
 | 
			
		||||
                if (!key) {
 | 
			
		||||
                    key = "action-list." +name.replace(/^.*:/,"");
 | 
			
		||||
                }
 | 
			
		||||
                var label = RED._(key);
 | 
			
		||||
                if (label === key) {
 | 
			
		||||
                    // no translation. convert `name` to description 
 | 
			
		||||
                    label = name.replace(/(^.+:([a-z]))|(-([a-z]))/g, function() {
 | 
			
		||||
                        if (arguments[5] === 0) {
 | 
			
		||||
                            return arguments[2].toUpperCase();
 | 
			
		||||
                        } else {
 | 
			
		||||
                            return " "+arguments[4].toUpperCase();
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                    missing.push(key);
 | 
			
		||||
                }
 | 
			
		||||
                def.label = label;
 | 
			
		||||
                def.label = getActionLabel(action)
 | 
			
		||||
            }
 | 
			
		||||
            //console.log("; missing:", missing);
 | 
			
		||||
 | 
			
		||||
            result.push({
 | 
			
		||||
                id:action,
 | 
			
		||||
                scope:shortcut?shortcut.scope:undefined,
 | 
			
		||||
@@ -79,6 +87,7 @@ RED.actions = (function() {
 | 
			
		||||
        add: addAction,
 | 
			
		||||
        remove: removeAction,
 | 
			
		||||
        get: getAction,
 | 
			
		||||
        getLabel: getActionLabel,
 | 
			
		||||
        invoke: invokeAction,
 | 
			
		||||
        list: listActions
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user