diff options
author | André Oliveira <37463445+SpecialAro@users.noreply.github.com> | 2022-08-18 01:01:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-18 01:01:22 +0100 |
commit | d00b8bed31fc2313733ec7ea226350ba46b3d4d5 (patch) | |
tree | 81b2350e99691d4ea7d41a1cc5edda23cdf216e3 /src/helpers/translation-helpers.ts | |
parent | Upgrade 'electron' to '20.0.3' (#558) (diff) | |
download | ferdium-app-d00b8bed31fc2313733ec7ea226350ba46b3d4d5.tar.gz ferdium-app-d00b8bed31fc2313733ec7ea226350ba46b3d4d5.tar.zst ferdium-app-d00b8bed31fc2313733ec7ea226350ba46b3d4d5.zip |
fix: dependabot critical issues with translator (#559)
Diffstat (limited to 'src/helpers/translation-helpers.ts')
-rw-r--r-- | src/helpers/translation-helpers.ts | 21 |
1 files changed, 11 insertions, 10 deletions
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 @@ | |||
1 | import fetch from 'node-fetch'; | 1 | import fetch from 'node-fetch'; |
2 | import translateGoogle from 'translate-google'; | 2 | import translateGoogle from 'google-translate-api-x'; |
3 | import { LIVE_API_FERDIUM_LIBRETRANSLATE } from '../config'; | 3 | import { LIVE_API_FERDIUM_LIBRETRANSLATE } from '../config'; |
4 | 4 | ||
5 | export async function translateTo( | 5 | export async function translateTo( |
@@ -12,16 +12,17 @@ export async function translateTo( | |||
12 | 'FERDIUM ERROR: An error occured. Please select less text to translate or try again later.'; | 12 | 'FERDIUM ERROR: An error occured. Please select less text to translate or try again later.'; |
13 | 13 | ||
14 | if (translatorEngine === 'Google') { | 14 | if (translatorEngine === 'Google') { |
15 | try { | 15 | const translationResult = await translateGoogle(text, { |
16 | const res = await translateGoogle(text, { | 16 | to: translateToLanguage, |
17 | to: translateToLanguage, | 17 | autoCorrect: true, |
18 | }); | 18 | }) |
19 | .then(res => ({ text: res.text, error: false })) | ||
20 | .catch(() => ({ text: errorText, error: true })); | ||
19 | 21 | ||
20 | return { text: res, error: false }; | 22 | return translationResult; |
21 | } catch { | 23 | } |
22 | return { text: errorText, error: true }; | 24 | |
23 | } | 25 | if (translatorEngine === 'LibreTranslate') { |
24 | } else if (translatorEngine === 'LibreTranslate') { | ||
25 | try { | 26 | try { |
26 | const res = await fetch(LIVE_API_FERDIUM_LIBRETRANSLATE, { | 27 | const res = await fetch(LIVE_API_FERDIUM_LIBRETRANSLATE, { |
27 | method: 'POST', | 28 | method: 'POST', |