From 3eeff8e8b4450443964bb5a1e77083083a8a42ed Mon Sep 17 00:00:00 2001 From: sienori Date: Thu, 3 Mar 2022 23:11:04 +0900 Subject: [PATCH] Open with DeepL translator on error --- src/_locales/en/messages.json | 3 +++ src/content/components/TranslatePanel.js | 14 +++++++++----- src/popup/components/ResultArea.js | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 4ce22b5..08f4558 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -26,6 +26,9 @@ "openInGoogleLabel": { "message": "Open in Google Translate" }, + "openInDeeplLabel": { + "message": "Open in DeepL Translator" + }, "copyLabel": { "message": "Copy" }, diff --git a/src/content/components/TranslatePanel.js b/src/content/components/TranslatePanel.js index fb99989..6ad604d 100644 --- a/src/content/components/TranslatePanel.js +++ b/src/content/components/TranslatePanel.js @@ -184,6 +184,7 @@ export default class TranslatePanel extends Component { const candidateStyles = { color: getSettings("candidateFontColor") }; + const translationApi = getSettings("translationApi"); return (
{errorMessage}
- - {browser.i18n.getMessage("openInGoogleLabel")} + + {translationApi === "google" ? + browser.i18n.getMessage("openInGoogleLabel") : + browser.i18n.getMessage("openInDeeplLabel")}

)} diff --git a/src/popup/components/ResultArea.js b/src/popup/components/ResultArea.js index 3564e5d..e53d0dc 100644 --- a/src/popup/components/ResultArea.js +++ b/src/popup/components/ResultArea.js @@ -14,11 +14,16 @@ const splitLine = text => { export default props => { const { resultText, candidateText, isError, errorMessage, targetLang } = props; const shouldShowCandidate = getSettings("ifShowCandidate"); + const translationApi = getSettings("translationApi"); + console.log(translationApi); const handleLinkClick = () => { const { inputText, targetLang } = props; const encodedText = encodeURIComponent(inputText); - const translateUrl = `https://translate.google.com/?sl=auto&tl=${targetLang}&text=${encodedText}`; + const translateUrl = translationApi === "google" ? + `https://translate.google.com/?sl=auto&tl=${targetLang}&text=${encodedText}` : + `https://www.deepl.com/translator#auto/${targetLang}/${encodedText}` + ; openUrl(translateUrl); }; @@ -29,7 +34,12 @@ export default props => { {isError &&

{errorMessage}

} {isError && (

- {browser.i18n.getMessage("openInGoogleLabel")} + + {translationApi === "google" ? + browser.i18n.getMessage("openInGoogleLabel") : + browser.i18n.getMessage("openInDeeplLabel") + } +

)}