Added i18n and legacy output label support

This commit is contained in:
Paul Wieland 2020-04-27 12:16:20 -04:00
parent 3e898c487a
commit 25aadc690a
2 changed files with 18 additions and 10 deletions

View File

@ -183,22 +183,29 @@
if (payloadProperty && topicProperty) { if (payloadProperty && topicProperty) {
lab = payloadProperty.vt; lab = payloadProperty.vt;
} else if (propertyCount > 1){ } else if (propertyCount > 1){
lab = propertyCount + ' properties'; lab = propertyCount + " " + this._("inject.label.properties");
} else if(propertyCount === 1){ } else if(propertyCount === 1){
lab = this.props[0].vt; lab = this.props[0].vt;
} }
// Friendly names
switch(lab){
case 'date': lab = 'timestamp'; break;
case 'str': lab = 'string'; break;
case 'num': lab = 'number'; break;
case 'bin': lab = 'buffer'; break;
case '': lab = 'nothing'; break;
}
} else { } else {
lab = 'legacy payload';
lab = this.payloadType;
if (lab === "json") {
try {
lab = typeof JSON.parse(this.payload);
if (lab === "object") {
if (Array.isArray(JSON.parse(this.payload))) { lab = "Array"; }
} }
} catch(e) {
return this._("inject.label.invalid");
}
}
}
var name = "inject.label."+lab;
var label = this._(name);
if (name !== label) { lab = label; }
return lab; return lab;
}, },

View File

@ -37,6 +37,7 @@
"stopped": "stopped", "stopped": "stopped",
"failed": "Inject failed: __error__", "failed": "Inject failed: __error__",
"label": { "label": {
"properties": "Properties",
"repeat": "Repeat", "repeat": "Repeat",
"flow": "flow context", "flow": "flow context",
"global": "global context", "global": "global context",