Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

词汇表的系统+编码兼容性测试 #67

Closed
anartigone opened this issue Jun 14, 2023 · 12 comments
Closed

词汇表的系统+编码兼容性测试 #67

anartigone opened this issue Jun 14, 2023 · 12 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@anartigone
Copy link

由于Windows系统下无法正常使用词汇表,在阅读过另一篇issue后,我进行了更详尽的测试,希望我的测试结果对以后的更新有所帮助。

操作系统:en-us_windows_10_enterprise_ltsc_2021_x64_dvd_d289cf96.iso
程序安装包:calibre-64bit-6.21.0.exe
插件安装包:Ebook-Translator-Calibre-Plugin_v2.0.2.zip

翻译文本:
Washington, D.C. (District of Columbia), the capital city and federal district of the United States of America.

保存格式:
washington.txt
编码:
UTF-8

词汇表文本:

Washington

D.C.

United States of America
美国

保存格式:
glossary.txt
编码:
UTF-8

插件设置 (默认以外的改动) :
偏好模式-高级模式
缓存-取消勾选 (否则会干扰测试结果)
输出格式-TXT
翻译词汇表-开启-glossary.txt

预期翻译结果:
Washington,D.C.(哥伦比亚特区) ,美国的首都和联邦特区。

实际翻译结果 (高级/批量模式相同) :
华盛顿特区(哥伦比亚特区) ,美利坚合众国的首都和联邦区。

对操作系统的深入测试:
系统和软件都是新装的,软件和插件配置都尽量保持了默认,以确保环境干净。
已排除文件权限问题,主程序是以管理员权限启动的,文本文件都是放在系统默认的文档目录里的。
在Linux和Mac OS系统下运行正常,同样的操作可以得到预期翻译结果,但测试了各种Windows (11pro, 10pro1809, ltsc2021, ltsb2016, win7sp1) 和各种calibre (6.21.0, 5.44, 3.48) 都不行。非windows系统则任何版本的calibre都能正常使用。

对文本编码的深入测试:
注:windows/linux代表生成txt所用的系统,linux下生成的没有使用windows line ending的txt文件在windows下打开会显示成下面这样

WashingtonD.C.United States of America美国 

  • windows-utf8:windows下失败,linux下出错。
    -linux下输出txt的内容直接为 华盛顿,{{id_00001}}(哥伦比亚特区),{{id_00002}}的首都和联邦区。
  • windows-ANSI:windows下失败,linux下失败。
  • windows-GBK:windows下失败,linux下出错。
    -linux下输出txt的内容直接为 华盛顿,{{id_00001}}(哥伦比亚特区),{{id_00002}}的首都和联邦区。
  • windows-GB2312:windows下失败,linux下失败。
  • windows-ISO2022:windows下失败,linux下正常。
    • 高级模式的校对上栏显示为{{id_00000}}, {{id_00001}} (District of Columbia), the capital city and federal district of the {{id_00002}}.,但输出正常。
  • windows-GB18030:windows下失败,linux下失败。
  • windows-utf16le:windows下失败,linux下失败。
  • windows-utf16be:windows下失败,linux下失败。
  • linux-utf8:windows下失败,linux下正常。
  • linux-utf8-win_line_ending:windows下失败,linux下正常。
    • 高级模式的校对上栏显示为{{id_00000}}, {{id_00001}} (District of Columbia), the capital city and federal district of the {{id_00002}}.,但输出正常。
  • linux-GBK:windows下失败,linux下失败。
  • linux-GBK-win_line_ending:windows下失败,linux下失败。
  • linux-GB18030:windows下失败,linux下失败。
  • linux-GB18030-win_line_ending:windows下失败,linux下失败。
  • linux-utf32:windows下失败,linux下失败。
  • linux-utf32-win_line_ending:windows下失败,linux下失败。
@bookfere
Copy link
Owner

谢谢提供详尽的测试数据,我们会利用此数据提升词汇表的可用性。

@bookfere bookfere added bug Something isn't working good first issue Good for newcomers labels Jun 15, 2023
@bookfere
Copy link
Owner

bookfere commented Jun 21, 2023

词汇表在 Windows 下不可用的问题是之前的版本错误处理换行导致的。请试用下面这个版本,看该功能是否可用:

ebook-translator-202306212355.zip

@anartigone
Copy link
Author

ebook-translator-202306212355.zip

ebook-translator-202306212355.zip的windows测试:

预期翻译结果:
Washington,D.C.(哥伦比亚特区) ,美国的首都和联邦特区。

实际翻译结果:

  • windows-utf8:
    华盛顿,D.C.(哥伦比亚特区),美利坚合众国的首都和联邦区。

  • windows-ISO2022:
    Washington,D.C.(哥伦比亚特区),美利坚合众国的首都和联邦区。

  • linux-utf8:
    Washington,D.C.(哥伦比亚特区),美利坚合众国的首都和联邦区。

  • linux-utf8-win_line_ending:
    Washington,D.C.(哥伦比亚特区),美利坚合众国的首都和联邦区。

其他编码的文件会报错:

 File "codecs.py", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 48: invalid continuation byte

或 

in position 0: invalid start byte

总结:
在高级模式校对中会显示成下面这样,也就是最多识别到前两处改动 (忽略) ,而第三处不能被能识别到 (替换) 。
{{id_00000}}, {{id_00001}} (District of Columbia), the capital city and federal district of the United States of America.

其他编码无法被解码的原因显而易见,目前没必要做过多兼容。

windows-utf8的词汇表只能识别到一个改动 (第二处) 的原因暂时无法推测,可能需要进一步测试。

@bookfere
Copy link
Owner

版本 v2.1.0 对词汇表功能做了一些修改,可以测试看看是否还存在此问题。

@anartigone
Copy link
Author

版本 v2.1.0 对词汇表功能做了一些修改,可以测试看看是否还存在此问题。

2.1.1 更新测试

预期翻译结果:
Washington,D.C.(哥伦比亚特区) ,美国的首都和联邦特区。

实际翻译结果:

  • windows-utf8:
    华盛顿州,D.C.(哥伦比亚特区),美国 的首府和联邦区。

  • linux-utf8:
    Washington,D.C.(哥伦比亚特区),美国 的首府和联邦区。

  • linux-utf8-win_line_ending:
    Washington,D.C.(哥伦比亚特区),美国 的首府和联邦区。

新问题

不勾选开启缓存会在输出时报错:

==============================
Time consuming: 0.0 minutes
翻译已完成。
==============================
开始转换电子书格式:
==============================
Converting XHTML to TXT...
TXT output written to C:\Users\ADMINI~1\AppData\Local\Temp\calibre__twf0xtj\po8vqv84.txt
Traceback (most recent call last):
  File "runpy.py", line 196, in _run_module_as_main
  File "runpy.py", line 86, in _run_code
  File "site.py", line 83, in <module>
  File "site.py", line 78, in main
  File "site.py", line 50, in run_entry_point
  File "calibre\utils\ipc\worker.py", line 215, in main
  File "calibre\utils\ipc\worker.py", line 150, in arbitrary_n
  File "calibre_plugins.ebook_translator.lib.conversion", line 108, in convert_book
  File "calibre_plugins.ebook_translator.lib.cache", line 220, in done
  File "calibre_plugins.ebook_translator.lib.cache", line 217, in destroy
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\com.bookfere.Calibre.EbookTranslator\\temp\\0fd4e12aab5b93df53e937b476577b99.db'

勾选开启缓存后输出正常,但随后用缓存管理器删除/清除时会报错 (重启主程序后可以删除) :

calibre, version 6.23.0
错误: Cannot open file or folder as it is in use: <p>Could not open the file: "C:\Users\ADMINI~1\AppData\Local\Temp\com.bookfere.Calibre.EbookTranslator\cache\0fd4e12aab5b93df53e937b476577b99.db". It is already opened in the following programs:<div>The main calibre program: C:\Program Files\Calibre2\calibre.exe

calibre 6.23  embedded-python: True
Windows-10-10.0.17763-SP0 Windows ('64bit', 'WindowsPE')
('Windows', '10', '10.0.17763')
Python 3.10.1
Windows: ('10', '10.0.17763', 'SP0', 'Multiprocessor Free')
Interface language: zh_CN
Successfully initialized third party plugins: Ebook Translator (2, 1, 1)
Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.cache", line 146, in clear
  File "calibre_plugins.ebook_translator.lib.cache", line 109, in clean
  File "calibre_plugins.ebook_translator.lib.cache", line 104, in remove
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\com.bookfere.Calibre.EbookTranslator\\cache\\0fd4e12aab5b93df53e937b476577b99.db'

总结

在linux下生成的两个词汇表都可以在windows下完美运作了,但是在windows生成的还有些奇怪,如果将linux下生成的词汇表在windows下另存为,则也会出现同样的问题 (第一行该被忽略的Washington→华盛顿州) 。

关于新出现的缓存问题,已经尝试过更改默认缓存路径到自定义路径,情况没有变化、使用主程序最新版6.23也没有变化、使用管理员权限运行主程序也没有变化。
删除、清除、更改路径、重置路径都需要在新开主程序时,也就是没有使用过翻译功能的状态下才能成功操作。如果翻译过再进行操作就会触发上面的报错 (缓存锁死) 。
如果需要的话我可以单独开一个新issue。

@bookfere
Copy link
Owner

好的,关于缓存的问题可以新开一个 issue,方便到时提交时引用。

@bookfere
Copy link
Owner

如果将linux下生成的词汇表在windows下另存为,则也会出现同样的问题

这句话指的是在 Linux 下创建词汇表,然后在 Windows 中打开再另存为吗?

@anartigone
Copy link
Author

如果将linux下生成的词汇表在windows下另存为,则也会出现同样的问题

这句话指的是在 Linux 下创建词汇表,然后在 Windows 中打开再另存为吗?

对的,这样做的意图是测试notepad.exe对换行符的影响。结果就是无论是在windows下创建的还是仅仅编辑过的词汇表文件都会对出现相同的兼容性问题。

@bookfere
Copy link
Owner

我用 Windows 的记事本程序直接创建的文本文件,以及在 Windows 的子系统 Unbuntu 中用 vim 创建后再用 Windows 的记事本程序打开另存的文本文件,都没能重现这个问题。能否把你出现这个问题的两种文本文件传上来,我测试一下。

@anartigone
Copy link
Author

我用 Windows 的记事本程序直接创建的文本文件,以及在 Windows 的子系统 Unbuntu 中用 vim 创建后再用 Windows 的记事本程序打开另存的文本文件,都没能重现这个问题。能否把你出现这个问题的两种文本文件传上来,我测试一下。

linux-utf8-windows-saved.txt
windows-utf8.txt

@bookfere
Copy link
Owner

再试试这个:

ebook-translator-202308201621.zip

@anartigone
Copy link
Author

再试试这个:

ebook-translator-202308201621.zip

太棒了,这下完美修复了,原来是和BOM有关

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants