Add option to change to second lang on web page
This commit is contained in:
parent
13739980f6
commit
53509a149a
|
@ -76,6 +76,9 @@
|
||||||
"ifCheckLangCaptionLabel": {
|
"ifCheckLangCaptionLabel": {
|
||||||
"message": "Detects the language of the selected text, and if it is the same as the target language, the button is not displayed."
|
"message": "Detects the language of the selected text, and if it is the same as the target language, the button is not displayed."
|
||||||
},
|
},
|
||||||
|
"ifChangeSecondLangOnPageCaptionLabel": {
|
||||||
|
"message": "Detects the language of the selected text, and if it is the same as the default target language, translate it into the second language."
|
||||||
|
},
|
||||||
|
|
||||||
"toolbarLabel": {
|
"toolbarLabel": {
|
||||||
"message": "Toolbar popup"
|
"message": "Toolbar popup"
|
||||||
|
|
|
@ -46,8 +46,7 @@ const getSelectedPosition = () => {
|
||||||
return selectedPosition;
|
return selectedPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
const translateText = async text => {
|
const translateText = async (text, targetLang = getSettings("targetLang")) => {
|
||||||
const targetLang = getSettings("targetLang");
|
|
||||||
const result = await translate(text, "auto", targetLang);
|
const result = await translate(text, "auto", targetLang);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
@ -142,7 +141,15 @@ export default class TranslateContainer extends Component {
|
||||||
const useClickedPosition = panelReferencePoint === "clickedPoint" && clickedPosition !== null;
|
const useClickedPosition = panelReferencePoint === "clickedPoint" && clickedPosition !== null;
|
||||||
const panelPosition = useClickedPosition ? clickedPosition : this.selectedPosition;
|
const panelPosition = useClickedPosition ? clickedPosition : this.selectedPosition;
|
||||||
|
|
||||||
const result = await translateText(this.selectedText);
|
let result = await translateText(this.selectedText);
|
||||||
|
if (getSettings("ifChangeSecondLangOnPage")) {
|
||||||
|
const targetLang = getSettings("targetLang");
|
||||||
|
const secondLang = getSettings("secondTargetLang");
|
||||||
|
const shouldSwitchSecondLang =
|
||||||
|
result.sourceLanguage === targetLang && result.percentage > 0 && targetLang !== secondLang;
|
||||||
|
if (shouldSwitchSecondLang) result = await translateText(this.selectedText, secondLang);
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
shouldShowPanel: true,
|
shouldShowPanel: true,
|
||||||
panelPosition: panelPosition,
|
panelPosition: panelPosition,
|
||||||
|
|
|
@ -28,6 +28,15 @@ export default [
|
||||||
options: langListOptions,
|
options: langListOptions,
|
||||||
useRawOptionName: true
|
useRawOptionName: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "secondTargetLang",
|
||||||
|
title: "secondTargetLangLabel",
|
||||||
|
captions: ["secondTargetLangCaptionLabel"],
|
||||||
|
type: "select",
|
||||||
|
default: defaultLangs.secondTargetLang,
|
||||||
|
options: langListOptions,
|
||||||
|
useRawOptionName: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "ifShowCandidate",
|
id: "ifShowCandidate",
|
||||||
title: "ifShowCandidateLabel",
|
title: "ifShowCandidateLabel",
|
||||||
|
@ -77,30 +86,19 @@ export default [
|
||||||
hr: true
|
hr: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ifChangeSecondLangOnPage",
|
||||||
|
title: "ifChangeSecondLangLabel",
|
||||||
|
captions: ["ifChangeSecondLangOnPageCaptionLabel"],
|
||||||
|
type: "checkbox",
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
category: "toolbarLabel",
|
category: "toolbarLabel",
|
||||||
elements: [
|
elements: [
|
||||||
{
|
|
||||||
id: "ifChangeSecondLang",
|
|
||||||
title: "ifChangeSecondLangLabel",
|
|
||||||
captions: ["ifChangeSecondLangCaptionLabel"],
|
|
||||||
type: "checkbox",
|
|
||||||
default: false,
|
|
||||||
childElements: [
|
|
||||||
{
|
|
||||||
id: "secondTargetLang",
|
|
||||||
title: "secondTargetLangLabel",
|
|
||||||
captions: ["secondTargetLangCaptionLabel"],
|
|
||||||
type: "select",
|
|
||||||
default: defaultLangs.secondTargetLang,
|
|
||||||
options: langListOptions,
|
|
||||||
useRawOptionName: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "waitTime",
|
id: "waitTime",
|
||||||
title: "waitTimeLabel",
|
title: "waitTimeLabel",
|
||||||
|
@ -109,6 +107,13 @@ export default [
|
||||||
min: 0,
|
min: 0,
|
||||||
placeholder: 500,
|
placeholder: 500,
|
||||||
default: 500
|
default: 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ifChangeSecondLang",
|
||||||
|
title: "ifChangeSecondLangLabel",
|
||||||
|
captions: ["ifChangeSecondLangCaptionLabel"],
|
||||||
|
type: "checkbox",
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue