Skip to content

Commit

Permalink
Final i18n prep
Browse files Browse the repository at this point in the history
  • Loading branch information
Colm Doyle committed Apr 11, 2018
1 parent afe1c00 commit 5d0a350
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -3,7 +3,7 @@
* In production, you may want to use something like Express.js
* or Botkit to host a webserver and manage API calls
*/
const {TOKEN, PORT} = process.env,
const {TOKEN, PORT, LOCALE} = process.env,
triage = require('./triage'),
qs = require('querystring'),
axios = require('axios'),
Expand All @@ -18,7 +18,7 @@ function handleRequest(req, res){
directory: __dirname + '/locales'
});

i18n.setLocale('pirate'); // What language should TriageBot speak?
i18n.setLocale(LOCALE || 'pirate'); // What language should TriageBot speak?

let body = "";
req.on('data', data => body += data);
Expand Down
6 changes: 4 additions & 2 deletions locales/en.json
@@ -1,5 +1,7 @@
{
"There are %s request(s) pending in %s:": "blah blah blah %s blah blah blah %s:",
"There are `{{count}}` request(s) pending in {{channel}}:": "There are `{{count}}` request(s) pending in {{channel}}:",
"There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:": "There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:"
"There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:": "There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:",
"Here's how the *Triage Bot* works:": "Here's how the *Triage Bot* works:",
"I look at the last 1000 messages posted in this channel.\nI'll only review messages that have one of these reacji - {{pending_emojis}}.\nIf a message has one of these reacji - {{review_emojis}} - it's in progress.\nIf it has one of these reacji - {{addressed_emojis}} - it's done. Otherwise it's still pending.": "I look at the last 1000 messages posted in this channel.\nI'll only review messages that have one of these reacji - {{pending_emojis}}.\nIf a message has one of these reacji - {{review_emojis}} - it's in progress.\nIf it has one of these reacji - {{addressed_emojis}} - it's done. Otherwise it's still pending.",
"To publish this to the channel type `/triage publish`.": "To publish this to the channel type `/triage publish`."
}
7 changes: 7 additions & 0 deletions locales/ja.json
@@ -0,0 +1,7 @@
{
"There are `{{count}}` request(s) pending in {{channel}}:": "There are `{{count}}` request(s) pending in {{channel}}:",
"There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:": "There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:",
"Here's how the *Triage Bot* works:": "Here's how the *Triage Bot* works:",
"I look at the last 1000 messages posted in this channel.\nI'll only review messages that have one of these reacji - {{pending_emojis}}.\nIf a message has one of these reacji - {{review_emojis}} - it's in progress.\nIf it has one of these reacji - {{addressed_emojis}} - it's done. Otherwise it's still pending.": "I look at the last 1000 messages posted in this channel.\nI'll only review messages that have one of these reacji - {{pending_emojis}}.\nIf a message has one of these reacji - {{review_emojis}} - it's in progress.\nIf it has one of these reacji - {{addressed_emojis}} - it's done. Otherwise it's still pending.",
"To publish this to the channel type `/triage publish`.": "To publish this to the channel type `/triage publish`."
}
7 changes: 5 additions & 2 deletions locales/pirate.json
@@ -1,4 +1,7 @@
{
"There are `{{count}}` request(s) pending in {{channel}}:": "There be `{{count}}` request(s) waiting to walk the plank of {{channel}}:",
"There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:": "There be `{{count}}` request(s) under the steely :eyes: of a crewmate in {{channel}}:"
"There are `{{count}}` request(s) pending in {{channel}}:": "There be `{{count}}` request(s) waiting to walk the plank in {{channel}}:",
"There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:": "There be `{{count}}` request(s) being looked :eyes: by a fellow crewmate in {{channel}}:",
"Here's how the *Triage Bot* works:": "Here's how the the scurvy *Triage Bot* works:",
"I look at the last 1000 messages posted in this channel.\nI'll only review messages that have one of these reacji - {{pending_emojis}}.\nIf a message has one of these reacji - {{review_emojis}} - it's in progress.\nIf it has one of these reacji - {{addressed_emojis}} - it's done. Otherwise it's still pending.": "I look 1000 leagues under the sea to messages posted in this channel.\nI'll only review messages that have one of these reacji - {{pending_emojis}}.\nIf a message has one of these reacji - {{review_emojis}} - it's walking the plank as we speak!.\nIf it has one of these reacji - {{addressed_emojis}} - it's in Davy Jones' locker. Otherwise it's still pending.",
"To publish this to the channel type `/triage publish`.": "To tell yer crewmates about this tale, type `/triage publish`."
}
24 changes: 4 additions & 20 deletions settings.json
Expand Up @@ -7,32 +7,16 @@

"pending": {
"title": "There are `{{count}}` request(s) pending in {{channel}}:",
"emojis": [ "red_circle", "large_blue_circle", "white_circle" ]
"emojis": [ ":red_circle:", ":large_blue_circle:", ":white_circle:" ]
},

"review": {
"title": "There are `{{count}}` request(s) being looked :eyes: at in {{channel}}:",
"emojis": [ "eyes" ]
"emojis": [ ":eyes:", ":sunglasses:" ]
},

"addressed": {
"title": "There are `{{count}}` request(s) addressed in {{channel}}:",
"emojis": [ "white_check_mark" ]
},

"help": [
{
"color": "#fff",
"text": "\n"
},
{
"mrkdwn_in": [ "text", "pretext" ],
"pretext": "Here's how the *Triage Bot* works:",
"text": "I look at messages posted in here since yesterday.\nI only care about messages that have :red_circle:, :large_blue_circle:, or :white_circle:.\nIf a messages has :eyes: reaction, it's in progress. \nIf it has a :white_check_mark:, it's done. Otherwise, it's still pending.\n"
},
{
"mrkdwn_in": [ "text", "pretext" ],
"pretext": "To publish this to the channel type `/triage publish`."
}
]
"emojis": [ ":white_check_mark:" ]
}
}
32 changes: 28 additions & 4 deletions triage.js
Expand Up @@ -38,8 +38,8 @@ function getRequest(settings, message) {

// flags based on reactions
let reactions = (message.reactions || []).map(r => r.name);
let addressed = settings.addressed.emojis.some(e => reactions.includes(e));
let review = settings.review.emojis.some(e => reactions.includes(e)) && !addressed;
let addressed = settings.addressed.emojis.some(e => reactions.includes(e.replace(/:/g, '')));
let review = settings.review.emojis.some(e => reactions.includes(e.replace(/:/g, ''))) && !addressed;
let pending = emoji && !review && !addressed;

let id = message.ts.replace('.', ''); // deep link id
Expand Down Expand Up @@ -68,8 +68,32 @@ function buildMessage(payload, requests, settings) {
message.text = settings.display.map(map).join('\n\n\n');

// attach instructions if not publish else make public
let pending_emojis = settings.pending.emojis.join(', ');
let review_emojis = settings.review.emojis.join(', ');
let addressed_emojis = settings.addressed.emojis.join(', ');
let help_text = [
"I look at the last 1000 messages posted in this channel.",
"I'll only review messages that have one of these reacji - {{pending_emojis}}.",
"If a message has one of these reacji - {{review_emojis}} - it's in progress.",
"If it has one of these reacji - {{addressed_emojis}} - it's done. Otherwise it's still pending."
]
let attachment = [
{
color: "#fff",
text: "\n"
},
{
mrkdwn_in: ["text", "pretext"],
pretext: i18n.__("Here's how the *Triage Bot* works:"),
text: i18n.__(help_text.join("\n"), { pending_emojis: pending_emojis, review_emojis: review_emojis, addressed_emojis: addressed_emojis})
},
{
mrkdwn_in: ["pretext"],
pretext: i18n.__("To publish this to the channel type `/triage publish`.")
}
];
if (publish_test.test(payload.text)) message.response_type = 'in_channel';
else message.attachments = settings.help;
else message.attachments = attachment;

return message;
}
Expand All @@ -92,7 +116,7 @@ function buildSection(settings, requests, payload, name) {
let title = i18n.__(settings[name].title, {count: filtered.length, channel: '<#'+channel_id+'|'+channel_name+'>' }); // section title
title = title.replace(/&lt;/g, `<`); // Lightweight encoding of HTML Entities
title = title.replace(/&gt;/g, `>`); // Lightweight encoding of HTML Entities
let items = filtered.map(r => `:${r.emoji}: ${baseUrl + r.id}`); // section line item
let items = filtered.map(r => `${r.emoji} ${baseUrl + r.id}`); // section line item
let text = [title].concat(items).join('\n'); // combined text
return text;
}
Expand Down

0 comments on commit 5d0a350

Please sign in to comment.