Skip to content

Commit

Permalink
Fixed the bug that caused DeepL to not work properly. fixed yihong061…
Browse files Browse the repository at this point in the history
  • Loading branch information
bookfere committed Apr 18, 2023
1 parent e91e9ec commit bbeb2a9
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 29 deletions.
4 changes: 3 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from calibre.customize import InterfaceActionBase

from calibre_plugins.ebook_translator.utils import _z


__license__ = 'GPL v3'
__copyright__ = '2023, bookfere.com <[email protected]>'
Expand All @@ -9,7 +11,7 @@


class EbookTranslator(InterfaceActionBase):
name = 'Ebook Translator'
name = _z('Ebook Translator')
title = _(name)
supported_platforms = ['windows', 'osx', 'linux']
author = 'bookfere.com'
Expand Down
8 changes: 6 additions & 2 deletions components/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def layout(self):

def check_usage(text):
if text is not None:
usage.setText('Usage: {}'.format(text))
usage.setText(_('Usage: {}').format(text))
usage.setVisible(True)
else:
usage.setVisible(False)
Expand All @@ -111,11 +111,15 @@ def check_usage(text):
self.translate_worker.deleteLater)
self.translate_thread.start()

def translate_result(text):
target.setPlainText(text)
self.usage_worker.check.emit()
self.translate_worker.result.connect(translate_result)

def test_translate():
self.translate_worker.translate.emit(
source.toPlainText(), source_lang.currentText(),
target_lang.currentText())
self.translate_worker.result.connect(target.setPlainText)
translate.clicked.connect(test_translate)

def done(self, result):
Expand Down
2 changes: 1 addition & 1 deletion engines/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def parse(response):
result = eval(
self.engine_data.get('response'), {"response": response})
if is_str(result):
raise Exception(_('Resposne was parsed incorrectly.'))
raise Exception(_('Response was parsed incorrectly.'))
return result

return self.get_result(
Expand Down
7 changes: 2 additions & 5 deletions engines/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ def usage_info(data):
total = usage.get('character_limit')
used = usage.get('character_count')
left = total - used
return '{} total, {} used, {} left'.format(total, used, left)
return _('{} total, {} used, {} left').format(total, used, left)

return self.get_result(
self.endpoint.get('usage'), callback=usage_info, silence=True,
headers={'Authorization': 'DeepL-Auth-Key %s' % self.api_key})

def translate(self, text):
headers = {
'Content-Type': 'application/json',
'Authorization': 'DeepL-Auth-Key %s' % self.api_key,
}
headers = {'Authorization': 'DeepL-Auth-Key %s' % self.api_key}

data = {
'text': text,
Expand Down
Binary file modified translations/es.mo
Binary file not shown.
13 changes: 11 additions & 2 deletions translations/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Ebook Translator Calibre Plugin\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-04-17 17:25+0800\n"
"POT-Creation-Date: 2023-04-18 18:14+0800\n"
"PO-Revision-Date: 2023-04-17 14:17+0800\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -18,6 +18,9 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Ebook Translator"
msgstr "Traductor de libros electrónicos"

msgid "Translating..."
msgstr "Traduciendo..."

Expand All @@ -30,6 +33,9 @@ msgstr "Traducir"
msgid "Usage: checking..."
msgstr "Uso: verificación..."

msgid "Usage: {}"
msgstr "Uso: {}"

msgid "Custom Translation Engine"
msgstr "Motor de Traducción Personalizado"

Expand Down Expand Up @@ -114,9 +120,12 @@ msgstr "Se requiere una expresión para analizar la respuesta."
msgid "Custom"
msgstr "Personalizado"

msgid "Resposne was parsed incorrectly."
msgid "Response was parsed incorrectly."
msgstr "La respuesta fue analizada incorrectamente."

msgid "{} total, {} used, {} left"
msgstr "{} en total, {} utilizado(s), {} restante(s)"

msgid "Youdao"
msgstr "Youdao"

Expand Down
40 changes: 26 additions & 14 deletions translations/message.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Ebook Translator Calibre Plugin\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-04-17 17:25+0800\n"
"POT-Creation-Date: 2023-04-18 18:14+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,6 +17,10 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: __init__.py:14
msgid "Ebook Translator"
msgstr ""

#: components/engine.py:40
msgid "Translating..."
msgstr ""
Expand All @@ -33,47 +37,51 @@ msgstr ""
msgid "Usage: checking..."
msgstr ""

#: components/engine.py:131
#: components/engine.py:101
msgid "Usage: {}"
msgstr ""

#: components/engine.py:135
msgid "Custom Translation Engine"
msgstr ""

#: components/engine.py:140
#: components/engine.py:144
msgid "Add"
msgstr ""

#: components/engine.py:141
#: components/engine.py:145
msgid "Delete"
msgstr ""

#: components/engine.py:144 main.py:574
#: components/engine.py:148 main.py:574
msgid "Clear"
msgstr ""

#: components/engine.py:145
#: components/engine.py:149
msgid "Reset"
msgstr ""

#: components/engine.py:146
#: components/engine.py:150
msgid "Verify"
msgstr ""

#: components/engine.py:147 main.py:272
#: components/engine.py:151 main.py:272
msgid "Save"
msgstr ""

#: components/engine.py:187
#: components/engine.py:191
msgid "Engine data format is valid."
msgstr ""

#: components/engine.py:203
#: components/engine.py:207
msgid "The engine name is already in use."
msgstr ""

#: components/engine.py:211 main.py:770
#: components/engine.py:215 main.py:770
msgid "The setting was saved."
msgstr ""

#: components/engine.py:217
#: components/engine.py:221
msgid "No custom engine to delete."
msgstr ""

Expand All @@ -93,7 +101,7 @@ msgstr ""
msgid "API Key"
msgstr ""

#: engines/base.py:89 tests/test_deepl.py:44
#: engines/base.py:89 tests/test_deepl.py:45
msgid "Can not parse returned response. Raw data: {}"
msgstr ""

Expand Down Expand Up @@ -146,7 +154,11 @@ msgid "Custom"
msgstr ""

#: engines/custom.py:123
msgid "Resposne was parsed incorrectly."
msgid "Response was parsed incorrectly."
msgstr ""

#: engines/deepl.py:24
msgid "{} total, {} used, {} left"
msgstr ""

#: engines/youdao.py:14
Expand Down
Binary file modified translations/zh_CN.mo
Binary file not shown.
13 changes: 11 additions & 2 deletions translations/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Ebook Translator Calibre Plugin\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-04-17 17:25+0800\n"
"POT-Creation-Date: 2023-04-18 18:14+0800\n"
"PO-Revision-Date: 2023-04-17 14:17+0800\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -17,6 +17,9 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "Ebook Translator"
msgstr "电子书翻译器"

msgid "Translating..."
msgstr "翻译中……"

Expand All @@ -29,6 +32,9 @@ msgstr "翻译"
msgid "Usage: checking..."
msgstr "用量:检查中……"

msgid "Usage: {}"
msgstr "用量:{}"

msgid "Custom Translation Engine"
msgstr "自定义翻译引擎"

Expand Down Expand Up @@ -113,9 +119,12 @@ msgstr "用来解析响应的表达式是必填项。"
msgid "Custom"
msgstr "自定义"

msgid "Resposne was parsed incorrectly."
msgid "Response was parsed incorrectly."
msgstr "响应没有正确解析。"

msgid "{} total, {} used, {} left"
msgstr "总计 {},已用 {},剩余 {}"

msgid "Youdao"
msgstr "有道"

Expand Down
Binary file modified translations/zh_TW.mo
Binary file not shown.
13 changes: 11 additions & 2 deletions translations/zh_TW.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Ebook Translator Calibre Plugin\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-04-17 17:25+0800\n"
"POT-Creation-Date: 2023-04-18 18:14+0800\n"
"PO-Revision-Date: 2023-04-17 23:49+0800\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand All @@ -18,6 +18,9 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.1.1\n"

msgid "Ebook Translator"
msgstr "電子書翻譯器"

msgid "Translating..."
msgstr "翻譯中..."

Expand All @@ -30,6 +33,9 @@ msgstr "翻譯"
msgid "Usage: checking..."
msgstr "使用量:檢查中..."

msgid "Usage: {}"
msgstr "使用量:{}"

msgid "Custom Translation Engine"
msgstr "自訂翻譯引擎"

Expand Down Expand Up @@ -114,9 +120,12 @@ msgstr "必須提供剖析回應的運算式。"
msgid "Custom"
msgstr "自訂"

msgid "Resposne was parsed incorrectly."
msgid "Response was parsed incorrectly."
msgstr "回應剖析不正確。"

msgid "{} total, {} used, {} left"
msgstr "總計 {},已用 {},剩餘 {}"

msgid "Youdao"
msgstr "有道"

Expand Down

0 comments on commit bbeb2a9

Please sign in to comment.