Add i18n content for moved core nodes

This commit is contained in:
Nick O'Leary
2015-06-16 10:36:19 +01:00
parent 36bc2e6b06
commit 7d011dac99
24 changed files with 689 additions and 418 deletions

View File

@@ -1,5 +1,5 @@
<!--
Copyright 2013,2015 IBM Corp.
Copyright 2013,2014 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -16,20 +16,20 @@
<script type="text/x-red" data-template-name="serial in">
<div class="form-row node-input-serial">
<label for="node-input-serial"><i class="fa fa-random"></i> Serial Port</label>
<label for="node-input-serial"><i class="fa fa-random"></i> <span data-i18n="serial.label.serialport"></span></label>
<input type="text" id="node-input-serial">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
</script>
<script type="text/x-red" data-help-name="serial in">
<p>Reads data from a local serial port.</p>
<p>Can either <ul><li>wait for a "split" character (default \n). Also accepts hex notation (0x0a).</li>
<li>wait for a timeout in milliseconds for the first character received</li>
<li>wait to fill a fixed sized buffer</li></ul></p>
<li>Wait for a timeout in milliseconds for the first character received</li>
<li>Wait to fill a fixed sized buffer</li></ul></p>
<p>It then outputs <b>msg.payload</b> as either a UTF8 ascii string or a binary Buffer object.</p>
<p>If no split character is specified, or a timeout or buffer size of 0, then a stream of single characters is sent - again either as ascii chars or size 1 binary buffers.</p>
</script>
@@ -47,7 +47,7 @@
icon: "serial.png",
label: function() {
var serialNode = RED.nodes.node(this.serial);
return this.name||(serialNode?serialNode.label().split(":")[0]:"serial");
return this.name||(serialNode?serialNode.label().split(":")[0]:this._("serial.label.serial"));
},
labelStyle: function() {
return this.name?"node_label_italic":"";
@@ -57,12 +57,12 @@
<script type="text/x-red" data-template-name="serial out">
<div class="form-row node-input-serial">
<label for="node-input-serial"><i class="fa fa-random"></i> Serial Port</label>
<label for="node-input-serial"><i class="fa fa-random"></i> <span data-i18n="serial.label.serialport"></span></label>
<input type="text" id="node-input-serial">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
</script>
@@ -86,7 +86,7 @@
align: "right",
label: function() {
var serialNode = RED.nodes.node(this.serial);
return this.name||(serialNode?serialNode.label().split(":")[0]:"serial");
return this.name||(serialNode?serialNode.label().split(":")[0]:this._("serial.label.serial"));
},
labelStyle: function() {
return this.name?"node_label_italic":"";
@@ -97,17 +97,17 @@
<script type="text/x-red" data-template-name="serial-port">
<div class="form-row">
<label for="node-config-input-serialport"><i class="fa fa-random"></i> Serial Port</label>
<input type="text" id="node-config-input-serialport" style="width:60%;" placeholder="/dev/ttyUSB0"/>
<label for="node-config-input-serialport"><i class="fa fa-random"></i> <span data-i18n="serial.label.serialport"></span></label>
<input type="text" id="node-config-input-serialport" style="width:60%;" data-i18n="[placeholder]serial.placeholder.serialport">
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<table><tr>
<td width="102px"><i class="fa fa-wrench"></i> Settings</td>
<td width="100px">Baud Rate</td>
<td width="80px">Data Bits</td>
<td width="80px">Parity</td>
<td width="80px">Stop Bits</td>
<td width="102px"><i class="fa fa-wrench"></i> <span data-i18n="serial.label.settings"></span></td>
<td width="100px" data-i18n="serial.label.baudrate"></td>
<td width="80px" data-i18n="serial.label.databits"></td>
<td width="80px" data-i18n="serial.label.parity"></td>
<td width="80px" data-i18n="serial.label.stopbits"></td>
</tr><tr><td>&nbsp;</td>
<td>
<select type="text" id="node-config-input-serialbaud" style="width: 100px;">
@@ -138,11 +138,11 @@
</select>
</td><td>
<select type="text" id="node-config-input-parity" style="width: 80px;">
<option value="none">None</option>
<option value="even">Even</option>
<option value="mark">Mark</option>
<option value="odd">Odd</option>
<option value="space">Space</option>
<option value="none" data-i18n="serial.parity.none"></option>
<option value="even" data-i18n="serial.parity.even"></option>
<option value="mark" data-i18n="serial.parity.mark"></option>
<option value="odd" data-i18n="serial.parity.odd"></option>
<option value="space" data-i18n="serial.parity.space"></option>
</select>
</td><td>
<select type="text" id="node-config-input-stopbits" style="width: 80px;">
@@ -153,36 +153,36 @@
</tr></table><br/>
<div class="form-row">
<label><i class="fa fa-sign-in"></i> Input</label>
<label><i class="fa fa-sign-in"></i> <span data-i18n="serial.label.input"></span></label>
</div>
<div class="form-row" style="padding-left: 10px;">
Split input
<span data-i18n="serial.label.split"></span>
<select type="text" id="node-config-input-out" style="margin-left: 5px; width:200px;">
<option value="char">on the character</option>
<option value="time">after a timeout of</option>
<option value="count">into fixed lengths of</option>
<option value="char" data-i18n="serial.split.character"></option>
<option value="time" data-i18n="serial.split.timeout"></option>
<option value="count" data-i18n="serial.split.lengths"></option>
</select>
<input type="text" id="node-config-input-newline" style="width:50px;">
<span id="node-units"></span>
</div>
<div class="form-row" style="padding-left: 10px;">
and deliver
<span data-i18n="serial.label.deliver"></span>
<select type="text" id="node-config-input-bin" style="margin-left: 5px; width: 150px;">
<option value="false">ascii strings</option>
<option value="bin">binary buffers</option>
<option value="false" data-i18n="serial.output.ascii"></option>
<option value="bin" data-i18n="serial.output.binary"></option>
</select>
</div>
<br/>
<div id="node-config-addchar">
<div class="form-row">
<label><i class="fa fa-sign-out"></i> Output</label>
<label><i class="fa fa-sign-out"></i> <span data-i18n="serial.label.output"></span></label>
</div>
<div class="form-row">
<input style="width: 30px;margin-left: 10px; vertical-align: top;" type="checkbox" id="node-config-input-addchar"><label style="width: auto;" for="node-config-input-addchar">add split character to output messages</label>
<input style="width: 30px;margin-left: 10px; vertical-align: top;" type="checkbox" id="node-config-input-addchar"><label style="width: auto;" for="node-config-input-addchar"><span data-i18n="serial.addsplit"></span></label>
</div>
</div>
<div class="form-tips" id="tip-split">Tip: the "Split on" character is used to split the input into separate messages. It can also be added to every message sent out to the serial port.</div>
<div class="form-tips" id="tip-bin" hidden>Tip: In timeout mode timeout starts from arrival of first character.</div>
<div class="form-tips" id="tip-split"><span data-i18n="serial.tip.split"></span></div>
<div class="form-tips" id="tip-bin" hidden><span data-i18n="serial.tip.timeout"></span></div>
</script>
<script type="text/javascript">
@@ -203,7 +203,7 @@
label: function() {
this.serialbaud = this.serialbaud || 57600;
this.databits = this.databits || 8;
this.parity = this.parity || 'none';
this.parity = this.parity || this._("serial.label.none");
this.stopbits = this.stopbits || 1;
return this.serialport+":"+this.serialbaud+"-"+this.databits+this.parity.charAt(0).toUpperCase()+this.stopbits;
},

View File

@@ -52,7 +52,7 @@ module.exports = function(RED) {
this.serialConfig.newline);
node.addCh = "";
if (node.serialConfig.addchar == "true" || node.serialConfig.addchar === true) {
node.addCh = this.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0"); // jshint ignore:line
node.addCh = this.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0");
}
node.on("input",function(msg) {
if (msg.hasOwnProperty("payload")) {
@@ -76,13 +76,13 @@ module.exports = function(RED) {
}
});
node.port.on('ready', function() {
node.status({fill:"green",shape:"dot",text:"connected"});
node.status({fill:"green",shape:"dot",text:RED._("common.status.connected")});
});
node.port.on('closed', function() {
node.status({fill:"red",shape:"ring",text:"not connected"});
node.status({fill:"red",shape:"ring",text:RED._("common.status.not-connected")});
});
} else {
this.error("missing serial config");
this.error(RED._("serial.errors.missing-conf"));
}
this.on("close", function(done) {
@@ -108,7 +108,7 @@ module.exports = function(RED) {
if (node.serialConfig.out != "count") { buf = new Buffer(bufMaxSize); }
else { buf = new Buffer(Number(node.serialConfig.newline)); }
var i = 0;
node.status({fill:"grey",shape:"dot",text:"unknown"});
node.status({fill:"grey",shape:"dot",text:RED._("common.status.not-connected")});
node.port = serialPool.get(this.serialConfig.serialport,
this.serialConfig.serialbaud,
this.serialConfig.databits,
@@ -121,7 +121,7 @@ module.exports = function(RED) {
if (node.serialConfig.newline.substr(0,2) == "0x") {
splitc = new Buffer([parseInt(node.serialConfig.newline)]);
} else {
splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); // jshint ignore:line
splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0"));
}
this.port.on('data', function(msg) {
@@ -132,7 +132,7 @@ module.exports = function(RED) {
}
else {
// do the timer thing
if (node.serialConfig.out === "time") {
if (node.serialConfig.out === "time") {
if (node.tout) {
i += 1;
buf[i] = msg;
@@ -168,25 +168,24 @@ module.exports = function(RED) {
buf[i] = msg;
i += 1;
if ((msg === splitc[0]) || (i === bufMaxSize)) {
var n = new Buffer(i);
buf.copy(n,0,0,i);
if (node.serialConfig.bin !== "bin") { n = n.toString(); }
node.send({"payload":n});
n = null;
var m = new Buffer(i);
buf.copy(m,0,0,i);
if (node.serialConfig.bin !== "bin") { m = m.toString(); }
node.send({"payload":m});
m = null;
i = 0;
}
}
else { node.log("should never get here"); }
}
});
this.port.on('ready', function() {
node.status({fill:"green",shape:"dot",text:"connected"});
node.status({fill:"green",shape:"dot",text:RED._("common.status.connected")});
});
this.port.on('closed', function() {
node.status({fill:"red",shape:"ring",text:"not connected"});
node.status({fill:"red",shape:"ring",text:RED._("common.status.not-connected")});
});
} else {
this.error("missing serial config");
this.error(RED._("serial.errors.missing-conf"));
}
this.on("close", function(done) {
@@ -200,13 +199,13 @@ module.exports = function(RED) {
RED.nodes.registerType("serial in",SerialInNode);
var serialPool = (function() {
var serialPool = function() {
var connections = {};
return {
get:function(port,baud,databits,parity,stopbits,newline,callback) {
var id = port;
if (!connections[id]) {
connections[id] = (function() {
connections[id] = function() {
var obj = {
_emitter: new events.EventEmitter(),
serial: null,
@@ -218,15 +217,26 @@ module.exports = function(RED) {
}
//newline = newline.replace("\\n","\n").replace("\\r","\r");
var setupSerial = function() {
obj.serial = new serialp.SerialPort(port,{
baudrate: baud,
databits: databits,
parity: parity,
stopbits: stopbits,
parser: serialp.parsers.raw
},true, function(err, results) { if (err) { obj.serial.emit('error',err); } });
//if (newline == "") {
obj.serial = new serialp.SerialPort(port,{
baudrate: baud,
databits: databits,
parity: parity,
stopbits: stopbits,
parser: serialp.parsers.raw
},true, function(err, results) { if (err) { obj.serial.emit('error',err); } });
//}
//else {
// obj.serial = new serialp.SerialPort(port,{
// baudrate: baud,
// databits: databits,
// parity: parity,
// stopbits: stopbits,
// parser: serialp.parsers.readline(newline)
// },true, function(err, results) { if (err) obj.serial.emit('error',err); });
//}
obj.serial.on('error', function(err) {
RED.log.error("serial port "+port+" error "+err);
RED.log.error(RED._("serial.errors.error",{port:port,error:err.toString()}));
obj._emitter.emit('closed');
obj.tout = setTimeout(function() {
setupSerial();
@@ -234,7 +244,7 @@ module.exports = function(RED) {
});
obj.serial.on('close', function() {
if (!obj._closing) {
RED.log.error("serial port "+port+" closed unexpectedly");
RED.log.error(RED._("serial.errors.unexpected-close",{port:port}));
obj._emitter.emit('closed');
obj.tout = setTimeout(function() {
setupSerial();
@@ -242,23 +252,30 @@ module.exports = function(RED) {
}
});
obj.serial.on('open',function() {
RED.log.info("serial port "+port+" opened at "+baud+" baud "+databits+""+parity.charAt(0).toUpperCase()+stopbits);
RED.log.info(RED._("serial.onopen",{port:port,baud:baud,config: databits+""+parity.charAt(0).toUpperCase()+stopbits}));
if (obj.tout) { clearTimeout(obj.tout); }
//obj.serial.flush();
obj._emitter.emit('ready');
});
obj.serial.on('data',function(d) {
for (var z=0; z<d.length; z++) {
obj._emitter.emit('data',d[z]);
}
//console.log(Buffer.isBuffer(d),d.length,d);
//if (typeof d !== "string") {
// //d = d.toString();
for (var z=0; z<d.length; z++) {
obj._emitter.emit('data',d[z]);
}
//}
//else {
// obj._emitter.emit('data',d);
//}
});
obj.serial.on("disconnect",function() {
RED.log.error("serial port "+port+" gone away");
RED.log.error(RED._("serial.errors.disconnected",{port:port}));
});
}
setupSerial();
return obj;
}());
}();
}
return connections[id];
},
@@ -270,7 +287,7 @@ module.exports = function(RED) {
connections[port]._closing = true;
try {
connections[port].close(function() {
RED.log.info("serial port closed");
RED.log.info(RED._("serial.errors.closed",{port:port}));
done();
});
}
@@ -281,7 +298,7 @@ module.exports = function(RED) {
}
}
}
}());
}();
RED.httpAdmin.get("/serialports", RED.auth.needsPermission('serial.read'), function(req,res) {
serialp.list(function (err, ports) {

View File

@@ -0,0 +1,51 @@
{
"serial": {
"label": {
"serialport": "Serial Port",
"settings": "Settings",
"baudrate": "Baud Rate",
"databits": "Data Bits",
"parity": "Parity",
"stopbits": "Stop Bits",
"input": "Input",
"split": "Split input",
"deliver": "and deliver",
"output": "Output",
"serial": "serial",
"none": "none"
},
"placeholder": {
"serialport": "for example: /dev/ttyUSB0/"
},
"parity": {
"none": "None",
"even": "Even",
"mark": "Mark",
"odd": "Odd",
"space": "Space"
},
"split": {
"character": "on the character",
"timeout": "after a timeout of",
"length": "into fixed lengths of"
},
"output": {
"ascii": "ascii strings",
"binary": "binary buffers"
},
"addsplit": "add split character to output messages",
"tip": {
"split": "Tip: the \"Split on\" character is used to split the input into separate messages. It can also be added to every message sent out to the serial port.",
"timeout": "Tip: In timeout mode timeout starts from arrival of first character."
},
"onopen": "serial port __port__ opened at __baud__ baud __config__",
"errors": {
"missing-conf": "missing serial config",
"serial-port": "serial port",
"error": "serial port __port__ error: __error__",
"unexpected-close": "serial port __port__ closed unexpectedly",
"disconnected": "serial port __port__ disconnected",
"closed": "serial port __port__ closed"
}
}
}