From cbe17d2321b627ab1216882e80da779dacf69c3c Mon Sep 17 00:00:00 2001 From: itagagaki Date: Sun, 27 Dec 2020 14:08:25 +0900 Subject: [PATCH] Add ability to specify languages Added options to specify the language of the source and target texts. --- README.md | 6 ++- Thunderbird/Changelog | 4 ++ Thunderbird/_locales/en-US/messages.json | 20 +++++++++- Thunderbird/_locales/ja/messages.json | 20 +++++++++- Thunderbird/background.js | 6 ++- Thunderbird/options.html | 48 +++++++++++++++++++++--- Thunderbird/options.js | 22 +++++++++-- 7 files changed, 111 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b203670..c718c55 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,11 @@ Translate selected text with DeepL ## Overview -This extension for Thunderbird 68+ adds a "Translate with DeepL" item to the context menu. When you select text and use it, a tab will open up, and it will translate the text for you at DeepL. +This extension for Thunderbird 68+ adds a "Translate with DeepL" item to the context menu. When you select text and use it, a tab will open up, and it will translate the text for you at DeepL. You can also use Ctrl+T to translate. You can also choose to have it open in a new window instead of a tab. Please set it in the options page. +In the options page, you can also specify the language of the source and target texts. #### How to open the options page 1. Click the menu button and click Add-ons, or select Tools > Add-ons from the menu bar. @@ -16,10 +17,11 @@ Depending on the version of Thunderbird, the "Translate with DeepL" item may not In that case, please restart Thunderbird once. ## 概要 -Thunderbird 68+用のこの拡張機能は、コンテキストメニューに「DeepLで翻訳」の項目を追加します。テキストを選択してそれを使用するとタブが開き、DeepLでテキストを翻訳します。 +Thunderbird 68+用のこの拡張機能は、コンテキストメニューに「DeepLで翻訳」の項目を追加します。テキストを選択してそれを使用するとタブが開き、DeepLでテキストを翻訳します。Ctrl+Tで翻訳することもできます。 タブではなく新しいウィンドウで開くようにすることもできます。 オプションページで設定して下さい。 +オプションページでは原文と訳文の言語を指定することもできます。 #### オプションページの開き方 1. メニューボタンをクリックして アドオン を選択するか、メニューバーから ツール > アドオン を選択してください。 diff --git a/Thunderbird/Changelog b/Thunderbird/Changelog index 3097f95..c849cce 100644 --- a/Thunderbird/Changelog +++ b/Thunderbird/Changelog @@ -1,3 +1,7 @@ +2020-12-27 V1.2.0 +Added keyboard shortcut. Ctrl+T now opens DeepL. +Added options to specify the language of the source and target texts. + 2020-12-18 V1.1.0 Added options page. DeepL can now be opened in a new window. diff --git a/Thunderbird/_locales/en-US/messages.json b/Thunderbird/_locales/en-US/messages.json index fc4ec69..5c94f13 100644 --- a/Thunderbird/_locales/en-US/messages.json +++ b/Thunderbird/_locales/en-US/messages.json @@ -11,5 +11,23 @@ "tab": { "message": "tab" }, "window": { "message": "new window" }, "width": { "message": "width" }, - "height": { "message": "height" } + "height": { "message": "height" }, + + "source_lang": { "message": "Source" }, + "target_lang": { "message": "Target" }, + "lang_auto": { "message": "Auto" }, + "lang_de": { "message": "German" }, + "lang_en": { "message": "English" }, + "lang_en_gb": { "message": "English (British)" }, + "lang_en_us": { "message": "English (American)" }, + "lang_fr": { "message": "French" }, + "lang_it": { "message": "Italian" }, + "lang_ja": { "message": "Japanese" }, + "lang_es": { "message": "Spanish" }, + "lang_nl": { "message": "Dutch" }, + "lang_pl": { "message": "Polish" }, + "lang_pt": { "message": "Portuguese" }, + "lang_pt_br": { "message": "Portuguese (Brazilian)" }, + "lang_ru": { "message": "Russian" }, + "lang_zh": { "message": "Chinese" } } diff --git a/Thunderbird/_locales/ja/messages.json b/Thunderbird/_locales/ja/messages.json index 3f82575..a46659a 100644 --- a/Thunderbird/_locales/ja/messages.json +++ b/Thunderbird/_locales/ja/messages.json @@ -11,5 +11,23 @@ "tab": { "message": "タブ" }, "window": { "message": "新しいウィンドウ" }, "width": { "message": "幅" }, - "height": { "message": "高さ" } + "height": { "message": "高さ" }, + + "source_lang": { "message": "原文" }, + "target_lang": { "message": "訳文" }, + "lang_auto": { "message": "自動" }, + "lang_de": { "message": "ドイツ語" }, + "lang_en": { "message": "英語" }, + "lang_en_gb": { "message": "英語 (イギリス)" }, + "lang_en_us": { "message": "英語 (アメリカ)" }, + "lang_fr": { "message": "フランス語" }, + "lang_it": { "message": "イタリア語" }, + "lang_ja": { "message": "日本語" }, + "lang_es": { "message": "スペイン語" }, + "lang_nl": { "message": "オランダ語" }, + "lang_pl": { "message": "ポーランド語" }, + "lang_pt": { "message": "ポルトガル語" }, + "lang_pt_br": { "message": "ポルトガル語 (ブラジル)" }, + "lang_ru": { "message": "ロシア語" }, + "lang_zh": { "message": "中国語 (簡体字)" } } diff --git a/Thunderbird/background.js b/Thunderbird/background.js index 98bda8d..43c31cc 100644 --- a/Thunderbird/background.js +++ b/Thunderbird/background.js @@ -1,7 +1,9 @@ function goDeepL(text) { - const url = 'https://www.deepl.com/translator#?/?/'+encodeURI(text); - messenger.storage.local.get(['target', 'width', 'height'], function(result) { + messenger.storage.local.get(['target', 'width', 'height', 'source_lang', 'target_lang'], function(result) { + const source_lang = result.source_lang ? result.source_lang : '?'; + const target_lang = result.target_lang ? result.target_lang : '?'; + const url = 'https://www.deepl.com/translator#'+source_lang+'/'+target_lang+'/'+encodeURI(text); switch (result.target) { case "window": messenger.windows.create({url: url, type: "popup", width: Number(result.width), height: Number(result.height)}); diff --git a/Thunderbird/options.html b/Thunderbird/options.html index 7c14223..d08528c 100644 --- a/Thunderbird/options.html +++ b/Thunderbird/options.html @@ -7,12 +7,48 @@
- - - - (, - ) - +
+ + + + (, + ) + +
+
+ + + + +
diff --git a/Thunderbird/options.js b/Thunderbird/options.js index d305f7a..9cd406b 100644 --- a/Thunderbird/options.js +++ b/Thunderbird/options.js @@ -5,19 +5,35 @@ function saveOptions(e) { }); const width = document.getElementsByName('width')[0].value; const height = document.getElementsByName('height')[0].value; + const source_lang = document.getElementById('source_lang').value; + const target_lang = document.getElementById('target_lang').value; browser.storage.local.set({ "width": width, - "height": height + "height": height, + "source_lang": source_lang, + "target_lang": target_lang }); e.preventDefault(); } +function selectLangOption(id, lang) { + const select = document.getElementById(id); + if (select) { + if (!lang) { + lang = '?'; + } + select.value = lang; + } +} + function restoreOptions() { - browser.storage.local.get('target', function(result) { + browser.storage.local.get(['target', 'source_lang', 'target_lang'], function(result) { const target = result.target ? result.target : 'tab'; Array.from(document.getElementsByName('target')).forEach( elem => { elem.checked = elem.value == target; } ); + selectLangOption('source_lang', result.source_lang); + selectLangOption('target_lang', result.target_lang); }); } @@ -78,6 +94,6 @@ document.addEventListener('DOMContentLoaded', () => { restoreOptions(); }); -document.querySelectorAll('input').forEach(elem => { +document.querySelectorAll('input, select').forEach(elem => { elem.addEventListener("change", e => saveOptions(e)); });