From d00b8bed31fc2313733ec7ea226350ba46b3d4d5 Mon Sep 17 00:00:00 2001 From: André Oliveira <37463445+SpecialAro@users.noreply.github.com> Date: Thu, 18 Aug 2022 01:01:22 +0100 Subject: fix: dependabot critical issues with translator (#559) --- src/helpers/translation-helpers.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/helpers') diff --git a/src/helpers/translation-helpers.ts b/src/helpers/translation-helpers.ts index 215b2a49c..0edd95412 100644 --- a/src/helpers/translation-helpers.ts +++ b/src/helpers/translation-helpers.ts @@ -1,5 +1,5 @@ import fetch from 'node-fetch'; -import translateGoogle from 'translate-google'; +import translateGoogle from 'google-translate-api-x'; import { LIVE_API_FERDIUM_LIBRETRANSLATE } from '../config'; export async function translateTo( @@ -12,16 +12,17 @@ export async function translateTo( 'FERDIUM ERROR: An error occured. Please select less text to translate or try again later.'; if (translatorEngine === 'Google') { - try { - const res = await translateGoogle(text, { - to: translateToLanguage, - }); + const translationResult = await translateGoogle(text, { + to: translateToLanguage, + autoCorrect: true, + }) + .then(res => ({ text: res.text, error: false })) + .catch(() => ({ text: errorText, error: true })); - return { text: res, error: false }; - } catch { - return { text: errorText, error: true }; - } - } else if (translatorEngine === 'LibreTranslate') { + return translationResult; + } + + if (translatorEngine === 'LibreTranslate') { try { const res = await fetch(LIVE_API_FERDIUM_LIBRETRANSLATE, { method: 'POST', -- cgit v1.2.3-54-g00ecf