From 7c953f8244e0cb9a5b0afd2b09b2ada12b5faae2 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Mon, 8 Mar 2021 16:08:07 +0200 Subject: [PATCH] Add ignored document lang option (#265) This option allows you to list the locales for which you do not need to apply translation. --- src/_locales/en/messages.json | 8 +++++++- src/content/index.js | 4 ++++ src/settings/defaultSettings.js | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 3d1128b..acf2fe1 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -137,6 +137,12 @@ "secondTargetLangCaptionLabel": { "message": "Select the second target language." }, + "ignoredDocumentLangLabel": { + "message": "Ignore documents in the following languages" + }, + "ignoredDocumentLangCaptionLabel": { + "message": "Comma separated languages that do not need to be translated." + }, "waitTimeLabel": { "message": "Waiting time to translate" }, @@ -359,4 +365,4 @@ "openPopupDescription": { "message": "Open toolbar popup" } -} \ No newline at end of file +} diff --git a/src/content/index.js b/src/content/index.js index e112202..c2caa28 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -28,8 +28,12 @@ const handleMouseUp = async e => { if (!isLeftClick) return; if (isInPasswordField) return; if (isInThisElement) return; + removeTranslatecontainer(); + const ignoredDocumentLang = getSettings('ignoredDocumentLang').split(',').map(s => s.trim()).filter(s => !!s) + if (!!document.documentElement.lang && ignoredDocumentLang.includes(document.documentElement.lang)) return; + const selectedText = getSelectedText(); prevSelectedText = selectedText; if (selectedText.length === 0) return; diff --git a/src/settings/defaultSettings.js b/src/settings/defaultSettings.js index cb5690b..9c0c26e 100644 --- a/src/settings/defaultSettings.js +++ b/src/settings/defaultSettings.js @@ -39,6 +39,15 @@ export default [ options: langListOptions, useRawOptionName: true }, + { + id: "ignoredDocumentLang", + title: "ignoredDocumentLangLabel", + captions: ["ignoredDocumentLangCaptionLabel"], + type: "text", + default: "", + placeholder: "en, ru, ch", + new: true, + }, { id: "ifShowCandidate", title: "ifShowCandidateLabel",