From 51e6e2908500d06eda0255e6f4877d29b471bb18 Mon Sep 17 00:00:00 2001 From: fabio Date: Wed, 11 Dec 2019 09:56:57 +0100 Subject: [PATCH 1/2] support internationalisation --- arduino-cloud.html | 392 +++++----------------------- arduino-cloud.js | 50 ++-- locales/en-US/arduino-cloud.html | 268 +++++++++++++++++++ locales/en-US/arduino-cloud.json | 57 ++++ utils/arduino-connection-manager.js | 4 +- 5 files changed, 426 insertions(+), 345 deletions(-) create mode 100644 locales/en-US/arduino-cloud.html create mode 100644 locales/en-US/arduino-cloud.json diff --git a/arduino-cloud.html b/arduino-cloud.html index dcc9317..a748566 100644 --- a/arduino-cloud.html +++ b/arduino-cloud.html @@ -74,16 +74,17 @@ oneditprepare: function () { if (this.connection && this.connection !== "_ADD_") { - initThings(this.connection, this.thing); - initProperties(this.connection, this.thing, this.property, outs); + initThings(this.connection, this._,this.thing,); + initProperties(this.connection, this.thing, this.property, outs,this._); } $("select#node-input-connection").change((e) => { + var msg = this._("arduino-cloud.config.connection.placeholders.no-conn-selected"); const connection = $("#node-input-connection").val(); const thing_id = $("#node-input-thing").val(); if (connection === "_ADD_") { $("select#node-input-thing").empty(); - $("").appendTo("#node-input-thing"); + $("").appendTo("#node-input-thing"); if (this.defaultname) { $("#node-input-name").val(""); } @@ -92,7 +93,7 @@ if (thing_id !== "updating") { $("select#node-input-thing").empty(); $("select#node-input-property").empty(); - initThings(connection); + initThings(connection,this._); } } }); @@ -101,19 +102,21 @@ const property_id = $("#node-input-property").val(); const connection = $("#node-input-connection").val(); const thing_text = $("#node-input-thing").find('option:selected').text() - + var str; if (connection === "_ADD_") { $("select#node-input-property").empty(); - $("").appendTo("#node-input-property"); + str = this._("arduino-cloud.config.connection.placeholders.no-conn-selected"); + $("").appendTo("#node-input-property"); $("#node-input-property").trigger("change"); } else if (thing_id !== "updating" && property_id !== "updating" && thing_id !== "err") { if (thing_id === undefined || thing_id === null || thing_id === "") { $("select#node-input-property").empty(); - $("").appendTo("#node-input-property"); + str = this._("arduino-cloud.config.node.placeholders.no-thing-selected"); + $("").appendTo("#node-input-thing"); $("select#node-input-thing").val("updating"); - + var msg; $.getJSON(`things?${queryString}`, things => { $("select#node-input-thing").empty(); if (things && typeof (things) == "object" && things.error) { @@ -189,7 +192,8 @@ $("").appendTo("#node-input-property"); $("#node-input-thing").trigger("change"); } else if (things && Array.isArray(things) && things.length !== 0) { - $("").appendTo("#node-input-thing"); + msg=label_func("arduino-cloud.config.node.placeholders.thing-select"); + $("").appendTo("#node-input-thing"); for (const t of things) { $("").appendTo("#node-input-thing"); } @@ -199,13 +203,14 @@ $("#node-input-thing").trigger("change"); } else if (things && Array.isArray(things) && things.length === 0) { $("select#node-input-thing").empty(); - $("").appendTo("#node-input-thing"); + msg=label_func("arduino-cloud.config.node.placeholders.no-things-available"); + $("").appendTo("#node-input-thing"); $("select#node-input-property").empty(); - $("").appendTo("#node-input-property"); + $("").appendTo("#node-input-property"); } }); } - function initProperties(connection, thing_id, property_id, outs) { + function initProperties(connection, thing_id, property_id, outs, label_func) { let queryString = prepareQueryString(connection); if (!queryString || queryString === "") return; @@ -219,11 +224,13 @@ $.getJSON(`properties?${queryString}`, properties => { $("select#node-input-property").empty(); + var msg; if (properties && typeof (properties) == "object" && properties.error) { $("select#node-input-property").empty(); $("").appendTo("#node-input-property"); } else if ((properties && Array.isArray(properties) && properties.length !== 0)) { - $("").appendTo("#node-input-property"); + msg= label_func("arduino-cloud.config.node.placeholders.property-select"); + $("").appendTo("#node-input-property"); for (const p of properties) { if (outs > 0 || p.permission === "READ_WRITE") $("").appendTo("#node-input-property"); @@ -233,7 +240,8 @@ } $("#node-input-property").trigger("change"); } else if (properties && Array.isArray(properties) && properties.length === 0) { - $("").appendTo("#node-input-property"); + msg= label_func("arduino-cloud.config.node.placeholders.no-property-available"); + $("").appendTo("#node-input-property"); } }); } @@ -272,411 +280,151 @@ - + - - - - - - - \ No newline at end of file diff --git a/arduino-cloud.js b/arduino-cloud.js index 3295a66..7fb7f34 100644 --- a/arduino-cloud.js +++ b/arduino-cloud.js @@ -50,7 +50,7 @@ module.exports = function (RED) { this.status({}); },config.id); }else{ - this.status({ fill: "red", shape: "ring", text: "Connection Error" }); + this.status({ fill: "red", shape: "ring", text: "arduino-cloud.status.connection-error" }); } this.on('close', function (done) { connectionManager.deleteClientMqtt(connectionConfig.credentials.clientid, this.thing, this.propertyVariableName,config.id).then(() => { done(); }); @@ -88,7 +88,7 @@ module.exports = function (RED) { if (typeof msg.payload !== "object") { s = getStatus(msg.payload); }else{ - s="Object Sent" + s="arduino-cloud.status.object-sent"; } if (s != undefined) this.status({ fill: "grey", shape: "dot", text: s }); @@ -96,14 +96,14 @@ module.exports = function (RED) { this.status({}); } catch (err) { console.log(err); - this.status({ fill: "red", shape: "dot", text: "Error setting value" }); + this.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.error-setting-value" }); } }); this.on('close', function (done) { connectionManager.deleteClientHttp(connectionConfig.credentials.clientid).then(() => { done(); }); }); }else{ - this.status({ fill: "red", shape: "ring", text: "Connection Error" }); + this.status({ fill: "red", shape: "ring", text: "arduino-cloud.status.connection-error" }); } } } catch (err) { @@ -161,11 +161,14 @@ module.exports = function (RED) { }] } ); - this.status({ fill: "grey", shape: "dot", text: "Sent " + data.length + " elements" }); + var str = RED._("arduino-cloud.status.sent"); + str += data.length; + str += RED._("arduino-cloud.status.elements"); + this.status({ fill: "grey", shape: "dot", text: str }); } }catch (err) { console.log(err); - this.status({ fill: "red", shape: "dot", text: "Error getting value" }); + this.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.error-getting-value" }); } }); @@ -174,11 +177,11 @@ module.exports = function (RED) { }); } }else{ - this.status({ fill: "red", shape: "ring", text: "Connection Error" }); + this.status({ fill: "red", shape: "ring", text: "arduino-cloud.status.connection-error" }); } } catch (err) { console.log(err); - this.status({ fill: "red", shape: "dot", text: "Error getting value" }); + this.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.error-getting-value" }); } } } @@ -214,7 +217,7 @@ module.exports = function (RED) { } } }else{ - this.status({ fill: "red", shape: "ring", text: "Connection Error" }); + this.status({ fill: "red", shape: "ring", text: "arduino-cloud.status.connection-error" }); } } catch (err) { console.log(err); @@ -243,7 +246,7 @@ module.exports = function (RED) { } catch (err) { console.log(err); this.pollTimeoutPoll = setTimeout(() => { this.poll(connectionConfig, pollTime) }, pollTime * 1000); - this.status({ fill: "red", shape: "dot", text: "Error getting value" }); + this.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.error-getting-value" }); } } } @@ -283,19 +286,19 @@ module.exports = function (RED) { this.status({}); } catch (err) { console.log(err); - this.status({ fill: "red", shape: "dot", text: "Error getting value" }); + this.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.error-getting-value" }); } }); this.on('close', function (done) { connectionManager.deleteClientHttp(connectionConfig.credentials.clientid).then(() => { done(); }); }); }else{ - this.status({ fill: "red", shape: "ring", text: "Connection Error" }); + this.status({ fill: "red", shape: "ring", text: "arduino-cloud.status.connection-error" }); } } } catch (err) { console.log(err); - this.status({ fill: "red", shape: "dot", text: "Error getting value" }); + this.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.error-getting-value" }); } } } @@ -319,6 +322,7 @@ module.exports = function (RED) { async function getThingsOrProperties(req, res, thingsOrProperties) { let arduinoRestClient; + var str; try { if (req.query.clientid || req.query.clientsecret) { arduinoRestClient = await connectionManager.getClientHttp({ @@ -330,13 +334,15 @@ module.exports = function (RED) { } else if (req.query.connectionid) { const connectionConfig = RED.nodes.getNode(req.query.connectionid); if (!connectionConfig) { - console.log("No credentials available."); - return res.send(JSON.stringify({ error: "No credentials available." })); + str=RED._("arduino-cloud.connection-error.no-cred-available"); + console.log(str); + return res.send(JSON.stringify({ error: str })); } arduinoRestClient = await connectionManager.getClientHttp(connectionConfig); } else { - console.log("No credentials available."); - return res.send(JSON.stringify({ error: "No credentials available." })); + str=RED._("arduino-cloud.connection-error.no-cred-available"); + console.log(str); + return res.send(JSON.stringify({ error: str })); } if (thingsOrProperties === "things") { return res.send(JSON.stringify(await arduinoRestClient.getThings())); @@ -344,12 +350,14 @@ module.exports = function (RED) { const thing_id = req.query.thing_id; return res.send(JSON.stringify(await arduinoRestClient.getProperties(thing_id))); } else { - console.log("Wrong parameter in getThingsOrProperties."); - return res.send(JSON.stringify({ error: "Wrong parameter in getThingsOrProperties." })); + str=RED._("arduino-cloud.connection-error.wrong-param"); + console.log(str); + return res.send(JSON.stringify({ error: str })); } } catch (err) { + str=RED._("arduino-cloud.connection-error.wrong-cred-sys-unvail"); console.log(`Status: ${err.status}, message: ${err.error}`); - return res.send(JSON.stringify({ error: "Wrong credentials or system unavailable." })); + return res.send(JSON.stringify({ error: str })); } } RED.httpAdmin.get("/things", RED.auth.needsPermission('Property-in.read'), async function (req, res) { @@ -368,5 +376,5 @@ function getStatus(value) { else return value; } - return "Object Injected"; + return RED._("arduino-cloud.status.object-injected"); } \ No newline at end of file diff --git a/locales/en-US/arduino-cloud.html b/locales/en-US/arduino-cloud.html new file mode 100644 index 0000000..812d1c1 --- /dev/null +++ b/locales/en-US/arduino-cloud.html @@ -0,0 +1,268 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/locales/en-US/arduino-cloud.json b/locales/en-US/arduino-cloud.json new file mode 100644 index 0000000..20469a6 --- /dev/null +++ b/locales/en-US/arduino-cloud.json @@ -0,0 +1,57 @@ +{ + "arduino-cloud":{ + "config":{ + "node":{ + "connection":"Connection", + "thing":"Thing", + "property": "Property", + "name":"Name", + "hist-label":"Time filter", + "poll-label":"Poll Every", + "placeholders":{ + "name":"Name", + "no-thing-selected":"No thing selected", + "thing-select":"Select a thing", + "no-things-available":"No things available", + "property-select":"Select a property", + "no-property-available":"No properties available" + } + }, + "time":{ + "last":"last", + "seconds":"seconds", + "minutes":"minutes", + "hours":"hours", + "days":"days", + "weeks":"weeks" + + }, + "connection":{ + "client-id":"Client ID", + "client-secret":"Client secret", + "placeholders":{ + "name":"Application name", + "client-id":"Client ID", + "client-secret":"Client secret", + "no-conn-selected":"No connection selected" + } + } + + }, + "status":{ + "connection-error":"Connection Error", + "offline":"Offline", + "error-setting-value":"Error setting value", + "error-getting-value":"Error getting value", + "sent":"Sent ", + "elements":" elements", + "object-injected":"Object Injected", + "object-sent":"Object Sent" + }, + "connection-error":{ + "no-cred-available":"No credentials available.", + "wrong-param":"Wrong parameter in getThingsOrProperties.", + "wrong-cred-sys-unvail":"Wrong credentials or system unavailable." + } + } +} \ No newline at end of file diff --git a/utils/arduino-connection-manager.js b/utils/arduino-connection-manager.js index a215575..b178dd7 100644 --- a/utils/arduino-connection-manager.js +++ b/utils/arduino-connection-manager.js @@ -78,7 +78,7 @@ function getMqttOptions(clientId,token,RED){ RED.nodes.eachNode((n)=>{ if(n.type === "property in"){ const node = RED.nodes.getNode(n.id); - node.status({ fill: "red", shape: "dot", text: "Connection Error" }); + node.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.connection-error" }); } }); @@ -90,7 +90,7 @@ function getMqttOptions(clientId,token,RED){ RED.nodes.eachNode((n)=>{ if(n.type === "property in"){ const node = RED.nodes.getNode(n.id); - node.status({ fill: "red", shape: "dot", text: "Offline" }); + node.status({ fill: "red", shape: "dot", text: "arduino-cloud.status.offline" }); } }); }, From 4fbd33968e5b28ef76937517931d72bbcdecd3d5 Mon Sep 17 00:00:00 2001 From: fabio Date: Wed, 11 Dec 2019 10:16:12 +0100 Subject: [PATCH 2/2] fix tag --- arduino-cloud.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino-cloud.html b/arduino-cloud.html index a748566..1891c07 100644 --- a/arduino-cloud.html +++ b/arduino-cloud.html @@ -112,7 +112,7 @@ if (thing_id === undefined || thing_id === null || thing_id === "") { $("select#node-input-property").empty(); str = this._("arduino-cloud.config.node.placeholders.no-thing-selected"); - $("").appendTo("#node-input-property"); $("#node-input-property").trigger("change"); } else { $("select#node-input-property").empty();