Open with DeepL translator on error
This commit is contained in:
parent
c5cc4caaf9
commit
3eeff8e8b4
|
@ -26,6 +26,9 @@
|
||||||
"openInGoogleLabel": {
|
"openInGoogleLabel": {
|
||||||
"message": "Open in Google Translate"
|
"message": "Open in Google Translate"
|
||||||
},
|
},
|
||||||
|
"openInDeeplLabel": {
|
||||||
|
"message": "Open in DeepL Translator"
|
||||||
|
},
|
||||||
"copyLabel": {
|
"copyLabel": {
|
||||||
"message": "Copy"
|
"message": "Copy"
|
||||||
},
|
},
|
||||||
|
|
|
@ -184,6 +184,7 @@ export default class TranslatePanel extends Component {
|
||||||
const candidateStyles = {
|
const candidateStyles = {
|
||||||
color: getSettings("candidateFontColor")
|
color: getSettings("candidateFontColor")
|
||||||
};
|
};
|
||||||
|
const translationApi = getSettings("translationApi");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -204,11 +205,14 @@ export default class TranslatePanel extends Component {
|
||||||
<p className="simple-translate-error" style={candidateStyles}>
|
<p className="simple-translate-error" style={candidateStyles}>
|
||||||
{errorMessage}
|
{errorMessage}
|
||||||
<br />
|
<br />
|
||||||
<a
|
<a href={translationApi === "google" ?
|
||||||
href={`https://translate.google.com/?sl=auto&tl=${currentLang}&text=${encodeURIComponent(selectedText)}`}
|
`https://translate.google.com/?sl=auto&tl=${currentLang}&text=${encodeURIComponent(selectedText)}` :
|
||||||
target="_blank"
|
`https://www.deepl.com/translator#auto/${currentLang}/${encodeURIComponent(selectedText)}`
|
||||||
>
|
}
|
||||||
{browser.i18n.getMessage("openInGoogleLabel")}
|
target="_blank">
|
||||||
|
{translationApi === "google" ?
|
||||||
|
browser.i18n.getMessage("openInGoogleLabel") :
|
||||||
|
browser.i18n.getMessage("openInDeeplLabel")}
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -14,11 +14,16 @@ const splitLine = text => {
|
||||||
export default props => {
|
export default props => {
|
||||||
const { resultText, candidateText, isError, errorMessage, targetLang } = props;
|
const { resultText, candidateText, isError, errorMessage, targetLang } = props;
|
||||||
const shouldShowCandidate = getSettings("ifShowCandidate");
|
const shouldShowCandidate = getSettings("ifShowCandidate");
|
||||||
|
const translationApi = getSettings("translationApi");
|
||||||
|
console.log(translationApi);
|
||||||
|
|
||||||
const handleLinkClick = () => {
|
const handleLinkClick = () => {
|
||||||
const { inputText, targetLang } = props;
|
const { inputText, targetLang } = props;
|
||||||
const encodedText = encodeURIComponent(inputText);
|
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);
|
openUrl(translateUrl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,7 +34,12 @@ export default props => {
|
||||||
{isError && <p className="error">{errorMessage}</p>}
|
{isError && <p className="error">{errorMessage}</p>}
|
||||||
{isError && (
|
{isError && (
|
||||||
<p className="translateLink">
|
<p className="translateLink">
|
||||||
<a onClick={handleLinkClick}>{browser.i18n.getMessage("openInGoogleLabel")}</a>
|
<a onClick={handleLinkClick}>
|
||||||
|
{translationApi === "google" ?
|
||||||
|
browser.i18n.getMessage("openInGoogleLabel") :
|
||||||
|
browser.i18n.getMessage("openInDeeplLabel")
|
||||||
|
}
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<div className="mediaButtons">
|
<div className="mediaButtons">
|
||||||
|
|
Loading…
Reference in a new issue