From 18507be5001f0a279ec406fe8d2fccbb725fe97f Mon Sep 17 00:00:00 2001 From: Luca Zorzi Date: Sat, 11 Oct 2014 12:59:26 +0200 Subject: [PATCH 1/2] Added localization --- accidentalbot.js | 27 +++++++++++++++------------ lang/en.json | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 lang/en.json diff --git a/accidentalbot.js b/accidentalbot.js index fe450c3..6a8945c 100644 --- a/accidentalbot.js +++ b/accidentalbot.js @@ -7,6 +7,9 @@ var webSocket = require('ws'); var channel = '#atp'; var webAddress = 'http://www.caseyliss.com/showbot'; var TITLE_LIMIT = 75; +var BOT_LANG = 'en'; + +var user_string = require('./lang/' + BOT_LANG + '.json'); var titles = []; var connections = []; @@ -35,8 +38,8 @@ function handleNewSuggestion(from, message) { } if (title.length > TITLE_LIMIT) { - client.say(from, 'That title is too long (over ' + TITLE_LIMIT + - ' characters); please try again.'); + client.say(from, user_string['titletoolong'] + TITLE_LIMIT + + user_string['characterstryagain']); title = ''; } if (title.length > 0) { @@ -59,7 +62,7 @@ function handleNewSuggestion(from, message) { sendToAll({operation: 'NEW', title: title}); } else { //client.say(channel, 'Sorry, ' + from + ', your title is a duplicate. Please try another!'); - client.say(from, 'Sorry, your title is a duplicate. Please try another!'); + client.say(from, user_string['duplicatetitle']); } } } @@ -77,10 +80,10 @@ function handleSendVotes(from, message) { return t.votes; }, true).to(3); - client.say(from, 'Three most popular titles:'); + client.say(from, user_string['threemostpopular']); for (var i = 0; i < titlesByVote.length; ++i) { var votes = titlesByVote[i]['votes']; - client.say(from, titlesByVote[i]['votes'] + ' vote' + (votes != 1 ? 's' : '') + ': " ' + titlesByVote[i].title + '"'); + client.say(from, titlesByVote[i]['votes'] + ' ' + (votes != 1 ? user_string['votes'] : user_string['vote']) + ': " ' + titlesByVote[i].title + '"'); } } @@ -102,17 +105,17 @@ function handleNewLink(from, message) { sendToAll({operation: 'NEWLINK', link: link}); } else { - client.say(from, "That doesn't look like a link to me."); + client.say(from, user_string['notalink']); } } function handleHelp(from) { - client.say(from, 'Options:'); - client.say(from, '!s {title} - suggest a title.'); - client.say(from, '!votes - get the three most highly voted titles.'); - client.say(from, '!link {URL} - suggest a link.'); - client.say(from, '!help - see this message.'); - client.say(from, 'To see titles/links, go to: ' + webAddress); + client.say(from, user_string['options']); + client.say(from, user_string['helpsuggest']); + client.say(from, user_string['helpvotes']); + client.say(from, user_string['helplink']); + client.say(from, user_string['helphelp']); + client.say(from, user_string['helpviewtitles'] + webAddress); } var client = new irc.Client('irc.freenode.net', 'accidentalbot', { diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..43b8c94 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,15 @@ +{ + "titletoolong": "That title is too long (over ", + "characterstryagain": " characters); please try again.", + "duplicatetitle": "Sorry, your title is a duplicate. Please try another!", + "threemostpopular": "Three most popular titles:", + "vote": "vote", + "votes": "votes", + "notalink": "That doesn't look like a link to me.", + "options": "Options:", + "helpsuggest": "!s {title} - suggest a title.", + "helpvotes": "!votes - get the three most highly voted titles.", + "helplink": "!link {URL} - suggest a link.", + "helphelp": "!help - see this message.", + "helpviewtitles": "To see titles/links, go to: " +} \ No newline at end of file From 9fa67332189d397bcf48c28df3498d01b3d9c2b9 Mon Sep 17 00:00:00 2001 From: Luca Zorzi Date: Sat, 11 Oct 2014 12:59:39 +0200 Subject: [PATCH 2/2] Added Italian translation --- lang/it.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lang/it.json diff --git a/lang/it.json b/lang/it.json new file mode 100644 index 0000000..c80d9a6 --- /dev/null +++ b/lang/it.json @@ -0,0 +1,15 @@ +{ + "titletoolong": "Quel titolo è troppo lungo (oltre ", + "characterstryagain": " caratteri); riprova.", + "duplicatetitle": "Mi spiace, il tuo titolo è un duplicato. Provane un altro!", + "threemostpopular": "I tre titoli più popolari:", + "vote": "voto", + "votes": "voti", + "notalink": "Quello non mi sembra un link.", + "options": "Opzioni:", + "helpsuggest": "!s {titolo} - suggerisci un titolo.", + "helpvotes": "!votes - ottieni i tre titoli più votati.", + "helplink": "!link {URL} - suggerisci un link.", + "helphelp": "!help - guarda questo messaggio.", + "helpviewtitles": "Per vedere i titoli/link, vai su: " +} \ No newline at end of file