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

@@ -23,34 +23,7 @@
(function() {
var twitterConfigNodeId = null;
var twitterConfigNodeIntervalId = null;
function showTwitterAuthStart() {
var pathname = document.location.pathname;
if (pathname.slice(-1) != "/") {
pathname += "/";
}
var callback = encodeURIComponent(location.protocol+"//"+location.hostname+":"+location.port+pathname+"twitter-credentials/"+twitterConfigNodeId+"/auth/callback");
$("#node-config-dialog-ok").button("disable");
$("#node-config-twitter-row").html('<div style="text-align: center; margin-top: 20px; "><a class="btn" id="node-config-twitter-start" href="twitter-credentials/'+twitterConfigNodeId+'/auth?callback='+callback+'" target="_blank">Click here to authenticate with Twitter.</a></div>');
$("#node-config-twitter-start").click(function() {
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
});
}
function updateTwitterScreenName(sn) {
$("#node-config-input-screen_name").val(sn);
$("#node-config-twitter-row").html('<label><i class="fa fa-user"></i> Twitter ID</label><span class="input-xlarge uneditable-input">'+sn+'</span>');
}
function pollTwitterCredentials(e) {
$.getJSON('credentials/twitter-credentials/'+twitterConfigNodeId,function(data) {
if (data.screen_name) {
updateTwitterScreenName(data.screen_name);
twitterConfigNodeIntervalId = null;
$("#node-config-dialog-ok").button("enable");
} else {
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
}
})
}
RED.nodes.registerType('twitter-credentials',{
category: 'config',
defaults: {
@@ -66,8 +39,36 @@
},
exportable: false,
oneditprepare: function() {
twitterConfigNodeId = this.id;
if (!this.screen_name || this.screen_name === "") {
var clickhere = this._("twitter.label.clickhere");
var twitterID = this._("twitter.label.twitter-id");
function showTwitterAuthStart() {
var pathname = document.location.pathname;
if (pathname.slice(-1) != "/") {
pathname += "/";
}
var callback = encodeURIComponent(location.protocol+"//"+location.hostname+":"+location.port+pathname+"twitter-credentials/"+twitterConfigNodeId+"/auth/callback");
$("#node-config-dialog-ok").button("disable");
$("#node-config-twitter-row").html('<div style="text-align: center; margin-top: 20px; "><a class="btn" id="node-config-twitter-start" href="twitter-credentials/'+twitterConfigNodeId+'/auth?callback='+callback+'" target="_blank">'+clickhere+'</a></div>');
$("#node-config-twitter-start").click(function() {
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
});
}
function updateTwitterScreenName(sn) {
$("#node-config-input-screen_name").val(sn);
$("#node-config-twitter-row").html('<label><i class="fa fa-user"></i> '+twitterID+'</label><span class="input-xlarge uneditable-input">'+sn+'</span>');
}
function pollTwitterCredentials(e) {
$.getJSON('credentials/twitter-credentials/'+twitterConfigNodeId,function(data) {
if (data.screen_name) {
updateTwitterScreenName(data.screen_name);
twitterConfigNodeIntervalId = null;
$("#node-config-dialog-ok").button("enable");
} else {
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
}
})
}
if (!this.screen_name || this.screen_name == "") {
showTwitterAuthStart();
} else {
if (this.credentials.screen_name) {
@@ -93,29 +94,27 @@
<script type="text/x-red" data-template-name="twitter in">
<div class="form-row">
<label for="node-input-twitter"><i class="fa fa-user"></i> Log in as</label>
<label for="node-input-twitter"><i class="fa fa-user"></i> <span data-i18n="twitter.label.twitter-id"></span></label>
<input type="text" id="node-input-twitter">
</div>
<div class="form-row">
<label for="node-input-user"><i class="fa fa-search"></i> Search</label>
<label for="node-input-user"><i class="fa fa-search"></i> <span data-i18n="twitter.label.search"></span></label>
<select type="text" id="node-input-user" style="display: inline-block; vertical-align: middle; width:60%;">
<option value="false">all public tweets</option>
<option value="true">the tweets of who you follow</option>
<option value="user">the tweets of specific users</option>
<option value="dm">your direct messages</option>
<option value="false" data-i18n="twitter.search.public"></option>
<option value="true" data-i18n="twitter.search.follow"></option>
<option value="user" data-i18n="twitter.search.user"></option>
<option value="dm" data-i18n="twitter.search.direct"></option>
</select>
</div>
<div class="form-row" id="node-input-tags-row">
<label for="node-input-tags"><i class="fa fa-tags"></i> <span id="node-input-tags-label">for</span></label>
<input type="text" id="node-input-tags" placeholder="comma-separated words, @ids, #tags">
<label for="node-input-tags"><i class="fa fa-tags"></i> <span id="node-input-tags-label" data-i18n="twitter.label.for"></span></label>
<input type="text" id="node-input-tags" data-i18n="[placeholder]twitter.placeholder.for">
</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>
<div class="form-tips">Tip: Use commas without spaces between multiple search terms. Comma = OR, Space = AND.
<br/>The Twitter API WILL NOT deliver 100% of all tweets.
<br/>Tweets of who you follow will include their retweets and favourites.</div>
<div class="form-tips"><span data-i18n="[html]twitter.tip"></span></div>
</script>
<script type="text/x-red" data-help-name="twitter in">
@@ -154,9 +153,9 @@
}
if (this.user == "dm") {
var user = RED.nodes.node(this.twitter);
return (user?user.label()+" ":"")+"DMs";
return (user?user.label()+" ":"")+this._("twitter.label.dmslabel");
} else if (this.user == "user") {
return this.tags+" tweets";
return this.tags+" "+this._("twitter.label.tweetslabel");
}
return this.tags;
},
@@ -164,18 +163,22 @@
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var userlabel = this._("twitter.label.user");
var userph = this._("twitter.placeholder.user");
var forlabel = this._("twitter.label.for");
var forph = this._("twitter.placeholder.for");
$("#node-input-user").change(function() {
var type = $("#node-input-user option:selected").val();
if (type == "user") {
$("#node-input-tags-row").show();
$("#node-input-tags-label").html("User");
$("#node-input-tags").attr("placeholder","comma-separated @twitter handles");
$("#node-input-tags-label").html(userlabel);
$("#node-input-tags").attr("placeholder",userph);
} else if (type == "dm") {
$("#node-input-tags-row").hide();
} else {
$("#node-input-tags-row").show();
$("#node-input-tags-label").html("for");
$("#node-input-tags").attr("placeholder","comma-separated words, @ids, #hashtags");
$("#node-input-tags-label").html(forlabel);
$("#node-input-tags").attr("placeholder",forph);
}
});
@@ -187,12 +190,12 @@
<script type="text/x-red" data-template-name="twitter out">
<div class="form-row">
<label for="node-input-twitter"><i class="fa fa-user"></i> Twitter</label>
<label for="node-input-twitter"><i class="fa fa-user"></i> <span data-i18n="twitter.label.twitter-id"></span></label>
<input type="text" id="node-input-twitter">
</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>

View File

@@ -16,7 +16,7 @@
module.exports = function(RED) {
"use strict";
var Ntwitter = require('twitter-ng');
var ntwitter = require('twitter-ng');
var OAuth= require('oauth').OAuth;
var request = require('request');
@@ -37,17 +37,17 @@ module.exports = function(RED) {
* Populate msg.location based on data found in msg.tweet.
*/
function addLocationToTweet(msg) {
if (msg.tweet) {
if (msg.tweet.geo) { // if geo is set, always set location from geo
if (msg.tweet.geo.coordinates && msg.tweet.geo.coordinates.length === 2) {
if(msg.tweet) {
if(msg.tweet.geo) { // if geo is set, always set location from geo
if(msg.tweet.geo.coordinates && msg.tweet.geo.coordinates.length === 2) {
if (!msg.location) { msg.location = {}; }
// coordinates[0] is lat, coordinates[1] is lon
msg.location.lat = msg.tweet.geo.coordinates[0];
msg.location.lon = msg.tweet.geo.coordinates[1];
msg.location.icon = "twitter";
}
} else if (msg.tweet.coordinates) { // otherwise attempt go get it from coordinates
if (msg.tweet.coordinates.coordinates && msg.tweet.coordinates.coordinates.length === 2) {
} else if(msg.tweet.coordinates) { // otherwise attempt go get it from coordinates
if(msg.tweet.coordinates.coordinates && msg.tweet.coordinates.coordinates.length === 2) {
if (!msg.location) { msg.location = {}; }
// WARNING! coordinates[1] is lat, coordinates[0] is lon!!!
msg.location.lat = msg.tweet.coordinates.coordinates[1];
@@ -70,7 +70,7 @@ module.exports = function(RED) {
var credentials = RED.nodes.getCredentials(this.twitter);
if (credentials && credentials.screen_name == this.twitterConfig.screen_name) {
var twit = new Ntwitter({
var twit = new ntwitter({
consumer_key: "OKjYEd1ef2bfFolV25G5nQ",
consumer_secret: "meRsltCktVMUI8gmggpXett7WBLd1k0qidYazoML6g",
access_token_key: credentials.access_token,
@@ -92,10 +92,10 @@ module.exports = function(RED) {
for (var i=0;i<users.length;i++) {
var user = users[i].replace(" ","");
twit.getUserTimeline({
screen_name:user,
trim_user:0,
count:1
},(function() {
screen_name:user,
trim_user:0,
count:1
},function() {
var u = user+"";
return function(err,cb) {
if (err) {
@@ -109,9 +109,9 @@ module.exports = function(RED) {
}
node.poll_ids.push(setInterval(function() {
twit.getUserTimeline({
screen_name:u,
trim_user:0,
since_id:node.since_ids[u]
screen_name:u,
trim_user:0,
since_id:node.since_ids[u]
},function(err,cb) {
if (cb) {
for (var t=cb.length-1;t>=0;t-=1) {
@@ -124,7 +124,7 @@ module.exports = function(RED) {
addLocationToTweet(msg);
}
node.send(msg);
if (t === 0) {
if (t == 0) {
node.since_ids[u] = tweet.id_str;
}
}
@@ -135,14 +135,14 @@ module.exports = function(RED) {
});
},60000));
}
}()));
}());
}
} else if (this.user === "dm") {
node.poll_ids = [];
twit.getDirectMessages({
screen_name:node.twitterConfig.screen_name,
trim_user:0,
count:1
screen_name:node.twitterConfig.screen_name,
trim_user:0,
count:1
},function(err,cb) {
if (err) {
node.error(err);
@@ -154,11 +154,11 @@ module.exports = function(RED) {
node.since_id = '0';
}
node.poll_ids.push(setInterval(function() {
twit.getDirectMessages({
screen_name:node.twitterConfig.screen_name,
trim_user:0,
since_id:node.since_id
},function(err,cb) {
twit.getDirectMessages({
screen_name:node.twitterConfig.screen_name,
trim_user:0,
since_id:node.since_id
},function(err,cb) {
if (cb) {
for (var t=cb.length-1;t>=0;t-=1) {
var tweet = cb[t];
@@ -170,7 +170,7 @@ module.exports = function(RED) {
addLocationToTweet(msg);
}
node.send(msg);
if (t === 0) {
if (t == 0) {
node.since_id = tweet.id_str;
}
}
@@ -191,9 +191,7 @@ module.exports = function(RED) {
if (bits.length == 4) {
if ((Number(bits[0]) < Number(bits[2])) && (Number(bits[1]) < Number(bits[3]))) {
st = { locations: node.tags };
}
else {
node.log("possible bad geo area format. Should be lower-left lon, lat, upper-right lon, lat");
node.log(RED._("twitter.status.using-geo",{location:node.tags.toString()}));
}
}
@@ -218,19 +216,19 @@ module.exports = function(RED) {
}
});
stream.on('limit', function(tweet) {
node.warn("tweet rate limit hit");
node.warn(RED._("twitter.errors.ratelimit"));
});
stream.on('error', function(tweet,rc) {
if (rc == 420) {
node.warn("Twitter rate limit hit");
node.warn(RED._("twitter.errors.ratelimit"));
} else {
node.warn("Stream error:"+tweet.toString()+" ("+rc+")");
node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc}));
}
setTimeout(setupStream,10000);
});
stream.on('destroy', function (response) {
if (this.active) {
node.warn("twitter ended unexpectedly");
node.warn(RED._("twitter.errors.unexpectedend"));
setTimeout(setupStream,10000);
}
});
@@ -243,10 +241,10 @@ module.exports = function(RED) {
node.error(err);
}
} else {
this.error("Invalid tag property");
this.error(RED._("twitter.errors.invalidtag"));
}
} else {
this.error("missing twitter credentials");
this.error(RED._("twitter.errors.missingcredentials"));
}
this.on('close', function() {
@@ -273,7 +271,7 @@ module.exports = function(RED) {
var node = this;
if (credentials && credentials.screen_name == this.twitterConfig.screen_name) {
var twit = new Ntwitter({
var twit = new ntwitter({
consumer_key: "OKjYEd1ef2bfFolV25G5nQ",
consumer_secret: "meRsltCktVMUI8gmggpXett7WBLd1k0qidYazoML6g",
access_token_key: credentials.access_token,
@@ -281,11 +279,11 @@ module.exports = function(RED) {
});
node.on("input", function(msg) {
if (msg.hasOwnProperty("payload")) {
node.status({fill:"blue",shape:"dot",text:"tweeting"});
node.status({fill:"blue",shape:"dot",text:RED._("twitter.status.tweeting")});
if (msg.payload.length > 140) {
msg.payload = msg.payload.slice(0,139);
node.warn("Tweet greater than 140 : truncated");
node.warn(RED._("twitter.errors.truncated"));
}
if (msg.media && Buffer.isBuffer(msg.media)) {
@@ -298,13 +296,13 @@ module.exports = function(RED) {
var r = request.post(signedUrl,function(err,httpResponse,body) {
if (err) {
node.error(err,msg);
node.status({fill:"red",shape:"ring",text:"failed"});
node.status({fill:"red",shape:"ring",text:RED._("twitter.status.failed")});
} else {
var response = JSON.parse(body);
if (response.errors) {
var errorList = response.errors.map(function(er) { return er.code+": "+er.message }).join(", ");
node.error("Send tweet failed: "+errorList,msg);
node.status({fill:"red",shape:"ring",text:"failed"});
node.error(RED._("twitter.errors.sendfail",{error:errorList}),msg);
node.status({fill:"red",shape:"ring",text:RED._("twitter.status.failed")});
} else {
node.status({});
}
@@ -317,14 +315,14 @@ module.exports = function(RED) {
} else {
twit.updateStatus(msg.payload, function (err, data) {
if (err) {
node.status({fill:"red",shape:"ring",text:"failed"});
node.status({fill:"red",shape:"ring",text:RED._("twitter.status.failed")});
node.error(err,msg);
}
node.status({});
});
}
}
else { node.warn("No payload to tweet"); }
else { node.warn(RED._("twitter.errors.nopayload")); }
});
}
}
@@ -340,16 +338,14 @@ module.exports = function(RED) {
"HMAC-SHA1"
);
RED.httpAdmin.get('/twitter-credentials/:id/auth', function(req, res) {
RED.httpAdmin.get('/twitter-credentials/:id/auth', function(req, res){
var credentials = {};
oa.getOAuthRequestToken({
oauth_callback: req.query.callback
},function(error, oauth_token, oauth_token_secret, results) {
oauth_callback: req.query.callback
},function(error, oauth_token, oauth_token_secret, results){
if (error) {
var resp = '<h2>Oh no!</h2>'+
'<p>Something went wrong with the authentication process. The following error was returned:<p>'+
'<p><b>'+error.statusCode+'</b>: '+error.data+'</p>'+
'<p>One known cause of this type of failure is if the clock is wrong on system running Node-RED.';
var error = {statusCode: 401, data: "dummy error"};
var resp = RED._("twitter.errors.oautherror",{statusCode: error.statusCode, errorData: error.data});
res.send(resp)
} else {
credentials.oauth_token = oauth_token;
@@ -360,7 +356,7 @@ module.exports = function(RED) {
});
});
RED.httpAdmin.get('/twitter-credentials/:id/auth/callback', function(req, res, next) {
RED.httpAdmin.get('/twitter-credentials/:id/auth/callback', function(req, res, next){
var credentials = RED.nodes.getCredentials(req.params.id);
credentials.oauth_verifier = req.query.oauth_verifier;
@@ -368,17 +364,17 @@ module.exports = function(RED) {
credentials.oauth_token,
credentials.token_secret,
credentials.oauth_verifier,
function(error, oauth_access_token, oauth_access_token_secret, results) {
if (error) {
function(error, oauth_access_token, oauth_access_token_secret, results){
if (error){
RED.log.error(error);
res.send("something in twitter oauth broke.");
res.send(RED._("twitter.errors.oauthbroke"));
} else {
credentials = {};
credentials.access_token = oauth_access_token;
credentials.access_token_secret = oauth_access_token_secret;
credentials.screen_name = "@"+results.screen_name;
RED.nodes.addCredentials(req.params.id,credentials);
res.send("<html><head></head><body>Authorised - you can close this window and return to Node-RED</body></html>");
res.send(RED._("twitter.errors.authorized"));
}
}
);

View File

@@ -0,0 +1,43 @@
{
"twitter": {
"label": {
"twitter-id":"Twitter ID",
"search": "Search",
"for": "for",
"user": "User",
"dmslabel": "DMs",
"tweetslabel": "tweets",
"clickhere": "Click here to authenticate with Twitter."
},
"placeholder": {
"for": "comma-separated words, @ids, #tags",
"user": "comma-separated @twitter handles"
},
"search": {
"public": "all public tweets",
"follow": "the tweets of who you follow",
"user": "the tweets of specific users",
"direct": "your direct messages"
},
"tip": "Tip: Use commas without spaces between multiple search terms. Comma = OR, Space = AND.<br/>The Twitter API WILL NOT deliver 100% of all tweets.<br/>Tweets of who you follow will include their retweets and favourites.",
"status": {
"using-geo": "Using geo location: __location__",
"tweeting": "tweeting",
"failed":"failed"
},
"errors": {
"ratelimit":"tweet rate limit hit",
"streamerror":"stream error: __error__ (__rc__)",
"unexpectedend":"stream ended unexpectedly",
"invalidtag":"invalid tag property",
"missingcredentials":"missing twitter credentials",
"truncated":"truncated tweet greater than 140 characters",
"sendfail":"send tweet failed: __error__",
"nopayload":"no payload to tweet",
"oauthbroke":"something in twitter oauth broke.",
"oautherror": "<html><head></head><body><p>Something went wrong with the authentication process. The following error was returned:</p><p><b>__statusCode__</b>: __errorData__</p><p>One known cause of this type of failure is if the clock is wrong on system running Node-RED</p></body></html>",
"authorized": "<html><head></head><body><p>Authorised - you can close this window and return to Node-RED</p></body></html>"
}
}
}