Skip to content

Commit

Permalink
#6 strip XML/HTML tags before sending to translate (#14)
Browse files Browse the repository at this point in the history
#6 strip XML/HTML tags before sending to translate
  • Loading branch information
walokra authored and henrycity committed Oct 2, 2018
1 parent 3486a96 commit 482544c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const axios = require('axios');
const franc = require('franc');
const striptags = require('striptags');
const translate = require('google-translate-api');
const RtmClient = require('@slack/client').RtmClient;
const RTM_EVENTS = require('@slack/client').RTM_EVENTS;
Expand Down Expand Up @@ -58,6 +59,6 @@ function sendMessage(thread_ts, text, channel) {
};

async function translateReply(text, userFirstName) {
const translatedTextInEnglish = (await translate(text, {to: 'en'})).text;
const translatedTextInEnglish = (await translate(striptags(text), {to: 'en'})).text;
return `${userFirstName} said "${translatedTextInEnglish}"`;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"babel-runtime": "^6.26.0",
"franc": "^4.0.0",
"google-translate-api": "^2.3.0"
"striptags": "^3.1.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var translateReply = function () {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return translate(text, { to: 'en' });
return translate(striptags(text), { to: 'en' });

case 2:
translatedTextInEnglish = _context2.sent.text;
Expand All @@ -37,6 +37,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a

var axios = require('axios');
var franc = require('franc');
var striptags = require('striptags');
var translate = require('google-translate-api');
var RtmClient = require('@slack/client').RtmClient;
var RTM_EVENTS = require('@slack/client').RTM_EVENTS;
Expand Down

0 comments on commit 482544c

Please sign in to comment.