Skip to content

Commit 722dda8

Browse files
committed
Added/improved features and fixed bugs:
1. Supported to customize translation text position and delete original content. resoved yihong0618#7 2. Supported to exclude original content by keyword and regular expression. resolved yihong0618#2 3. Added Baidu and Youdao translation engines. resolved yihong0618#3 4. Changed to save translated ebooks as a new book in Calibre library. 5. Supported to customize the color of translation text. 6. Supported to customize ChatGPT prompt word. resolved yihong0618#4 7. Ignored to translate phonetic symbols (e.g. Japanese). fixed yihong0618#3 8. Added Spanish as supported interface language. resolved yihong0618#5 9. Added disgnosis information to log. 10. Added "lang" attribute at translation element. 11. Fixed plugin icon disappearance when changing Calibre interface language. 12. Improved the functionality to extract original text.
1 parent 79bcdc9 commit 722dda8

37 files changed

+1964
-471
lines changed

README.md

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ebook Translator (A Calibre plugin)
22

3-
A Calibre plugin to translate ebook into a specified language (the translated text will be added after original text).
3+
A Calibre plugin to translate ebook into a specified language (optionally keeping the original content).
44

55
---
66

@@ -9,60 +9,89 @@ A Calibre plugin to translate ebook into a specified language (the translated te
99
* Support languages supported by the selected translation engine (e.g. Google Translate supports 134 languages)
1010
* Support multiple translation engines, including Google Translate, ChatGPT, and DeepL
1111
* Support all ebook formats supported by Calibre (48 input formats, 20 output formats)
12-
* Support to translate more than one ebooks, the translation process of each book is carried out simultaneously without affecting one another
13-
* Support caching translated content, no need to re-translate after request failure or network interruption
12+
* Support to translate more than one ebooks. The translation process of each book is carried out simultaneously without affecting one another
13+
* Support caching translated content, with no need to re-translate after request failure or network interruption
1414
* Provide a large number of customization settings, such as saving translated ebooks to Calibre library or designated location
1515

1616
---
1717

1818
## Settings
1919

20-
__[Output Path]__
20+
You can customize the plugin through "Content" and "Setting" panels.
2121

22-
* Library [default]: After the ebook is translated, it will be placed in Calibre library
23-
* Path: After the ebook is translated, it will be stored in specified directory
22+
### Content
2423

25-
When translating an ebook, you need to pay attention to the selected output format. If the selected output format is an existing format in Calibre library, the original input format file will be backed up by renaming. Therefore, it is not recommended to select the same output format as the input format. If you really need to use the same format for output, it is recommended to specify the path to store.
24+
__[ Translation Position ]__
2625

27-
__[Translation Engine]__
26+
* __Add after original__ [default]: Add the translation text after original text
27+
* __Add before original__: Add the translation text before original text
28+
* __Add without original__: Add the translation text and delete original text
2829

29-
* Google [default]: Free translation engine
30-
* ChatGPT: API key required
31-
* DeepL: API key required
32-
* DeepL(Pro): API key required
30+
__[ Translation Color ]__
31+
32+
* __Color Value__: CSS color value, e.g., #666666, grey, rgb(80, 80, 80)
33+
34+
You can click the [Select] button to select a color from color palette, or enter the color value manually. Please refer to "[color value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value)" on MDN documentation for details. If left blank no customized color will be used.
35+
36+
__[ Do not Translate ]__
37+
38+
* __Normal__ [default]: Exclude content by keyword (one keyword per line)
39+
* __Normal(case-sensitive)__: Exclude content by case-sensitive keyword (one keyword per line)
40+
* __Regular Expression__: Exclude content by Regular Expression rule (one rule per line)
41+
42+
For regular expression syntax, please refer to "[Regular Expression Syntax](https://docs.python.org/3/library/re.html#regular-expression-syntax)" on Python documentation.
43+
44+
### Setting
45+
46+
__[ Output Path ]__
47+
48+
* __Library__ [default]: After the ebook is translated, it will be placed in Calibre library
49+
* __Path__: After the ebook is translated, it will be stored in specified directory
50+
51+
__[ Translation Engine ]__
52+
53+
* __Google__ [default]: Free translation engine
54+
* __ChatGPT__: API key required
55+
* __DeepL__: API key required
56+
* __DeepL(Pro)__: API key required
3357

3458
Except for Google, who does not require an API key, other translation engines require you to register a corresponding account and pay to obtain an API key.
3559

3660
According to the response information sample provided by DeepL official website, the program can run properly, but due to the lack of DeepL's API key, the actual operation status is unknown.
3761

38-
If you choose to use a translation engine that requires payment, it is recommended to go to its official documentation to check the pricing rules. For example, ChatGPT uses its official tool [Tokenizer](https://platform.openai.com/tokenizer) to estimate how many tokens will be consumed to translate the amount of words in order to estimate the cost.
62+
If you opt for a paid translation engine, we recommend you to refer to its official documentation for pricing rules. For example, ChatGPT uses its official tool, [Tokenizer](https://platform.openai.com/tokenizer), to estimate the number of tokens required to translate a given amount of text in order to provide a cost estimate.
63+
64+
__[ ChatGPT Prompt ]__
65+
66+
* __For auto detecting source language__: Customize ChatGPT prompt to translate from 'Auto detect' source language
67+
* __For specifying source language__: Customize ChatGPT prompt to translate from specified source language
3968

40-
__[Network Proxy]__
69+
__[ Network Proxy ]__
4170

42-
* Enable [default unchecked]: Enable network proxy
43-
* Host: Support IP and domain name
44-
* Port: Range 0-65536
45-
* Test: Test the connectivity of proxy
71+
* __Enable__ [default unchecked]: Enable network proxy
72+
* __Host__: Support IP and domain name
73+
* __Port__: Range 0-65536
74+
* __Test__: Test the connectivity of proxy
4675

47-
__[Cache]__
76+
__[ Cache ]__
4877

49-
* Enable [default checked]: Enable to cache translated content
50-
* Clear: Delete all caches
78+
* __Enable__ [default checked]: Enable to cache translated content
79+
* __Clear__: Delete all caches
5180

5281
Enabling the caching function can avoid re-translation of translated content after request failure or network interruption. You can also check the amount of disk space occupied by the cache here, and click [Clear] button to delete all caches. Note that if a translation job is currently in progress, the [Clear] button will be disabled to use.
5382

54-
__[Request]__
83+
__[ Request ]__
5584

56-
* Attempt Times [default 3]: The number of times to attempt if the request to translation engine fails
57-
* Maximum Interval [default 5 seconds]: The maximum time interval to request translation engine
85+
* __Attempt Times__ [default 3]: The number of times to attempt if failed to request translation engine
86+
* __Maximum Interval__ [default 5 seconds]: The maximum time interval to request translation engine
5887

59-
A single request to translation engine can last up to 300 seconds. After the timeout, it will retry according to the specified attempt times, and the waiting time for each retry will be gradually increased. The request interval will be a random number between 0 and the specified maximum interval.
88+
A single request to translation engine can last up to 300 seconds. After the timeout, it will retry according to the specified attempt times, and the waiting time for each retry will be gradually increased. The request interval will be a random number between 1 and the specified maximum interval.
6089

61-
When using Google Translate API, which is currently available for free, it is recommended to increase the "Maximum Interval" to an appropriate value (more than 5 seconds is recommended) to prevent it from being flagged as abusive behavior by Google, which could lead to translation interruptions or denial of service. For paid translation engines, the "Maximum Interval" can be set to 0.
90+
When using Google Translate API, which is currently available for free, we recommend you to increase the "Maximum Interval" to an appropriate value (more than 5 seconds is recommended) to prevent it from being flagged as abusive behavior, which could lead to translation interruptions or denial of service. For paid translation engines, the "Maximum Interval" can be set to 1.
6291

63-
__[Log]__
92+
__[ Log ]__
6493

65-
* Display translation [Default checked]: The translation content will be displayed in real time from the respective log window of the translation job
94+
* __Display translation__ [Default checked]: The translation content will be displayed in real time from the respective log window of the translation job
6695

6796
---
6897

@@ -73,5 +102,6 @@ __[Log]__
73102
---
74103

75104
* GitHub: [https://github.com/bookfere/Ebook-Translator-Calibre-Plugin](https://github.com/bookfere/Ebook-Translator-Calibre-Plugin)
76-
* Release: [https://bookfere.com/post/1057.html](https://bookfere.com/post/1057.html)
77-
* Donate: [https://bookfere.com/donate](https://bookfere.com/donate)
105+
* MobileRead: [https://www.mobileread.com/forums/showthread.php?t=353052](https://www.mobileread.com/forums/showthread.php?t=353052)
106+
* Release: [https://github.com/bookfere/Ebook-Translator-Calibre-Plugin/releases](https://github.com/bookfere/Ebook-Translator-Calibre-Plugin/releases)
107+
* Donate: [https://www.paypal.com/paypalme/bookfere](https://www.paypal.com/paypalme/bookfere)

README.zh-CN.md

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,79 @@
1717

1818
## 设置说明
1919

20-
__【输出路径】__
20+
你可以通过“内容”和“设置”选项定制插件功能。
2121

22-
* 书库 [默认]:电子书翻译完成后会放入 Calibre 书库中
23-
* 路径:电子书翻译完成后会存放到指定目录中
22+
### 内容
2423

25-
翻译某本电子书时,需要注意所选取的输出格式,如果所选属输出格式是书库中已存在的格式,则作为输入的原格式文件会以重命名的方式进行备份。因此,不建议选择与输入格式相同的输出格式,如果确实需要使用同一格式输出,建议指定路径。
24+
__【 译文位置 】__
2625

27-
__【翻译引擎】__
26+
* __加在原文后__ [默认]:将译文添加到原文后
27+
* __加在原文前__:将译文添加到原文前
28+
* __不保留原文__:删除原文只保留译文
2829

29-
* Google [默认]:免费的翻译引擎
30-
* ChatGPT:需要 API 密钥
31-
* DeepL:需要 API 密钥
32-
* DeepL(Pro):需要 API 密钥
30+
__【 译文颜色 】__
31+
32+
* __颜色值__:CSS 颜色值,如 #666666, gry, rgb(80, 80, 80)
33+
34+
你可以通过点击【选择】按钮从调色盘选取颜色,也可以手动输入颜色值,颜色值可参考 MDN 有关“[颜色值](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value)”的文档。如果留空则不使用自定义颜色。
35+
36+
__【 忽略翻译 】__
37+
38+
* __关键词__:排除带关键词的内容(一行一条关键词)
39+
* __关键词(区分大小写)__:排除带关键词的内容,字母区分大小写(一行一条关键词)
40+
* __正则表达式__:排除匹配正则表达式规则的内容(一行一条规则)
41+
42+
正则表达式语法可参考 Python 官方文档中的“[正则表达式语法](https://docs.python.org/3/library/re.html#regular-expression-syntax)”。
43+
44+
### 设置
45+
46+
__【 输出路径 】__
47+
48+
* __书库__ [默认]:电子书翻译完成后会放入 Calibre 书库中
49+
* __路径__:电子书翻译完成后会存放到指定目录中
50+
51+
__【 翻译引擎 】__
52+
53+
* __Google__ [默认]:免费的翻译引擎
54+
* __ChatGPT__:需要 API 密钥
55+
* __DeepL__:需要 API 密钥
56+
* __DeepL(Pro)__:需要 API 密钥
3357

3458
注意,除了 Google 不需要 API 密钥外,其他翻译引擎都需要你注册相应账户(可能需要付费)获取 API 密钥才能使用。另外,由于插件在开发时缺少 DeepL 的 API 密钥,根据其官网提供的响应信息样例,程序可以正常运行,实际运行情况未知。
3559

3660
如果选择使用需要付费的翻译引擎,建议前往相应的官方文档查看计费规则。比如,ChatGPT,可以使用其官方提供的工具 [Tokenizer](https://platform.openai.com/tokenizer) 估算要翻译字数大约会消耗多少 token 以便预估费用。
3761

38-
__【网络代理】__
62+
__【 ChatGPT提示词 】__
63+
64+
* __自动探测来源语言时的提示词__:自定义当来源语言为“自动探测”时的翻译提示词
65+
* __指定来源语言时的提示词__:自定义当来源语言为指定语言时的翻译提示词
66+
67+
__【 网络代理 】__
3968

40-
* 开启 [默认不勾选]:开启网络代理
41-
* 主机:支持 IP 和域名
42-
* 端口:范围 0-65536
43-
* 测试:测试代理的连通性
69+
* __开启__ [默认不勾选]:开启网络代理
70+
* __主机__:支持 IP 和域名
71+
* __端口__:范围 0-65536
72+
* __测试__:测试代理的连通性
4473

45-
__缓存__
74+
__ 缓存 __
4675

47-
* 开启 [默认勾选]:开启翻译内容的缓存功能
48-
* 清除:删除所有缓存
76+
* __开启__ [默认勾选]:开启翻译内容的缓存功能
77+
* __清除__:删除所有缓存
4978

5079
开启缓存功能可以避免请求失败或网络中断后对已翻译过的内容进行重新翻译。另外,你还可以在这里看到缓存对磁盘空间的占用量,点击【清除】按钮可删除所有缓存。注意,如果当前有正在进行的翻译任务,则清除按钮不可用。
5180

52-
__请求__
81+
__ 请求 __
5382

54-
* 重试次数 [默认 3 次]:当请求翻译引擎失败后要重试的次数
55-
* 最大间隔 [默认 5 秒]:向翻译引擎发送请求的最大时间间隔
83+
* __重试次数__ [默认 3 次]:当请求翻译引擎失败后要重试的次数
84+
* __最大间隔__ [默认 5 秒]:向翻译引擎发送请求的最大时间间隔
5685

57-
插件对翻译引擎的每次请求最长可持续 300 秒,超时后会按照指定的次数进行重试,每次重试的等待时间会逐次加长。请求的时间间隔为 0 到指定最大间隔之间的随机数。
86+
插件对翻译引擎的每次请求最长可持续 300 秒,超时后会按照指定的次数进行重试,每次重试的等待时间会逐次加长。请求的时间间隔为 1 到指定最大间隔之间的随机数。
5887

59-
对于 Google 翻译这种目前可以免费使用的接口,建议酌情加长时间间隔(建议 5 秒以上),以免被 Google 翻译视为滥用,从而导致翻译中断或拒绝服务。付费翻译引擎则可以直接设为 0
88+
对于 Google 翻译这种目前可以免费使用的接口,建议酌情加长时间间隔(建议 5 秒以上),以免被 Google 翻译视为滥用,从而导致翻译中断或拒绝服务。付费翻译引擎则可以设为 1
6089

61-
__日志__
90+
__ 日志 __
6291

63-
* 显示翻译 [默认勾选]:可以在翻译任务各自的日志窗口实时查看翻译内容
92+
* __显示翻译__ [默认勾选]:可以在翻译任务各自的日志窗口实时查看翻译内容
6493

6594
---
6695

@@ -71,5 +100,6 @@ __【日志】__
71100
---
72101

73102
* GitHub:[https://github.com/bookfere/Ebook-Translator-Calibre-Plugin](https://github.com/bookfere/Ebook-Translator-Calibre-Plugin)
103+
* MobileRead: [https://www.mobileread.com/forums/showthread.php?t=353052](https://www.mobileread.com/forums/showthread.php?t=353052)
74104
* 发布页面:[https://bookfere.com/post/1057.html](https://bookfere.com/post/1057.html)
75105
* 赞赏页面:[https://bookfere.com/donate](https://bookfere.com/donate)

0 commit comments

Comments
 (0)