Skip to content

Commit

Permalink
Add ability to specify languages
Browse files Browse the repository at this point in the history
Added options to specify the language of the source and target texts.
  • Loading branch information
itagagaki committed Dec 27, 2020
1 parent 41a0eba commit cbe17d2
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 15 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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. メニューボタンをクリックして アドオン を選択するか、メニューバーから ツール > アドオン を選択してください。
Expand Down
4 changes: 4 additions & 0 deletions Thunderbird/Changelog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 19 additions & 1 deletion Thunderbird/_locales/en-US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
20 changes: 19 additions & 1 deletion Thunderbird/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "中国語 (簡体字)" }
}
6 changes: 4 additions & 2 deletions Thunderbird/background.js
Original file line number Diff line number Diff line change
@@ -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)});
Expand Down
48 changes: 42 additions & 6 deletions Thunderbird/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,48 @@

<body>
<form id="options">
<label>__MSG_open_in__ </label>
<label><input name="target" type="radio" value="tab">__MSG_tab__</label>
<label><input name="target" type="radio" value="window">__MSG_window__</label>
(<label>__MSG_width__: <input name="width" type="text" size="4" value="1200"></label>,
<label>__MSG_height__: <input name="height" type="text" size="4" value="800"></label>)
<label>__MSG_open_in_post__</label>
<div>
<label>__MSG_open_in__ </label>
<label><input name="target" type="radio" value="tab">__MSG_tab__</label>
<label><input name="target" type="radio" value="window">__MSG_window__</label>
(<label>__MSG_width__: <input name="width" type="text" size="4" value="1200"></label>,
<label>__MSG_height__: <input name="height" type="text" size="4" value="800"></label>)
<label>__MSG_open_in_post__</label>
</div>
<div style="margin-top: 1em;">
<label>__MSG_source_lang__: </label>
<select id="source_lang">
<option value="?" selected>__MSG_lang_auto__</option>
<option value="DE">__MSG_lang_de__</option>
<option value="EN">__MSG_lang_en__</option>
<option value="FR">__MSG_lang_fr__</option>
<option value="IT">__MSG_lang_it__</option>
<option value="JA">__MSG_lang_ja__</option>
<option value="ES">__MSG_lang_es__</option>
<option value="NL">__MSG_lang_nl__</option>
<option value="PL">__MSG_lang_pl__</option>
<option value="PT">__MSG_lang_pt__</option>
<option value="RU">__MSG_lang_ru__</option>
<option value="ZH">__MSG_lang_zh__</option>
</select>
<label>__MSG_target_lang__: </label>
<select id="target_lang">
<option value="?" selected>__MSG_lang_auto__</option>
<option value="DE">__MSG_lang_de__</option>
<option value="EN-GB">__MSG_lang_en_gb__</option>
<option value="EN-US">__MSG_lang_en_us__</option>
<option value="FR">__MSG_lang_fr__</option>
<option value="IT">__MSG_lang_it__</option>
<option value="JA">__MSG_lang_ja__</option>
<option value="ES">__MSG_lang_es__</option>
<option value="NL">__MSG_lang_nl__</option>
<option value="PL">__MSG_lang_pl__</option>
<option value="PT-PT">__MSG_lang_pt__</option>
<option value="PT-BR">__MSG_lang_pt_br__</option>
<option value="RU">__MSG_lang_ru__</option>
<option value="ZH">__MSG_lang_zh__</option>
</select>
</div>
</form>
<script src="options.js"></script>
</body>
Expand Down
22 changes: 19 additions & 3 deletions Thunderbird/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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));
});

0 comments on commit cbe17d2

Please sign in to comment.