使用 Python 翻译 CHM 帮助文档

此方法绝对切实可行

翻译成品项目: https://github.com/foyoux/InstallShield2020-Documents

效果预览

image-20210708210700961.png

安装 docts

pip install docts

pip install docts -i https://pypi.org/simple

必要时可加上 --upgrade 参数

安装本地化工具 Sisulizer

具体参考 docts 项目: https://github.com/foyoux/docts

在此不再赘述.

准备一个 chm 帮助文档文件

这里以 Sisulizer 的帮助文档为例

image.png

翻译步骤

1. 新建 Sisulizer 项目, 将 Sisulizer.chm 文件添加进去

111.gif

2. 保存项目, 然后在 Sisulizer 中导出提取出来的词句到 xlf 文件

222.gif

3. 使用 docts 进行翻译并导出

docts 中提供了一个默认的快捷翻译函数 todo

def todo(path: str):

    doc = Doc(path)
    
    doc.add_filter(filter_eq_symbol)
    
    doc.add_filter(filter_not_str)

    return doc.save_words()

尝试一下

from docts import *

xlf_path = r"H:\docts-demo\Sisulizer.xlf"

todo(xlf_path)

333.gif

在实际翻译过程中, 不可能有一种通用的翻译方法, 针对不同的文档, 我们可能有一些不想翻译, docts 中提供了一些方法进行过滤, 映射替换

  • add_filter
  • add_contain_filter
  • add_start_filter
  • add_end_filter
  • add_map
  • add_replace

具体参考 docts 项目: https://github.com/foyoux/docts

4. 在 Sisulizer 中导入翻译完成的 xlf 文件

444.gif

5. 在 Sisulizer 中建立翻译目标文件

555.gif

6. 完成

image.png

posted @ 2021-08-05 11:40  foyoux  阅读(843)  评论(0编辑  收藏  举报