From 56d4ec77e51abfe4f745bd90bc1013cd567c768c Mon Sep 17 00:00:00 2001 From: GuanZhang <44019025+guanzhangrtk@users.noreply.github.com> Date: Sun, 16 Jan 2022 00:14:31 +0900 Subject: [PATCH] Use the he library to decode HTML entities which may be present in translated text Fixes #16 --- package.json | 3 ++- src/dolmetscher.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 31f0994..e5e4c8d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "test": "mocha" }, "dependencies": { - "axios": "^0.24.0" + "axios": "^0.24.0", + "he": "^1.2.0" }, "devDependencies": { "chai": "^4.2.0", diff --git a/src/dolmetscher.js b/src/dolmetscher.js index a8bed72..176caa5 100644 --- a/src/dolmetscher.js +++ b/src/dolmetscher.js @@ -1,5 +1,6 @@ const axios = require("axios"); const fs = require("fs"); +const he = require("he"); const languages = require('./languages'); class BaseTranslator { @@ -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} `; }