Skip to content

Commit

Permalink
Use the he library to decode HTML entities which may be present in tr…
Browse files Browse the repository at this point in the history
…anslated text

Fixes nidhaloff#16
  • Loading branch information
guanzhangrtk committed Jan 15, 2022
1 parent ed483b6 commit 56d4ec7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test": "mocha"
},
"dependencies": {
"axios": "^0.24.0"
"axios": "^0.24.0",
"he": "^1.2.0"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/dolmetscher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const axios = require("axios");
const fs = require("fs");
const he = require("he");
const languages = require('./languages');

class BaseTranslator {
Expand Down Expand Up @@ -106,7 +107,7 @@ class GoogleTranslator extends BaseTranslator {
const body = html.slice(idx);
const translated = body.substring(0, body.indexOf("<"));

return translated;
return he.decode(translated);
} catch (err) {
throw `translation error: ${err} `;
}
Expand Down

0 comments on commit 56d4ec7

Please sign in to comment.