Skip to content

【开源自荐】EPUB 双语无损翻译 #7273

@BlackHole1

Description

@BlackHole1

简要

项目名: epub-translator
GitHub: https://github.com/oomol-lab/epub-translator
协议: MIT

功能特性

  • 多语言互译:支持 英文、中文、日文、西班牙语、法语、德语等主流语言互译。
  • 无损翻译:基于 AI 大模型 100% 保留原书的格式、插图、目录和排版
  • 双语对照:支持双语对照,方便学习和阅读
  • 插入提示词:指导 AI 翻译,如术语表,角色人名表等。
  • AI 模型可选:支持 DeepSeek、ChatGPT 等主流大模型
  • 高性能并行:AI 请求多路并发,快速翻译整本书籍
  • 错误自恢复:自动重试超时 & 速率限制,长书也能一次跑通

安装

pip install epub-translator

核心用法示例

from epub_translator import LLM, translate, Language

llm = LLM(
  key="<LLM-API-KEY>", # LLM 的 API key
  url="https://api.deepseek.com", # LLM 的 base URL
  model="deepseek-chat", # LLM 的模型名
  token_encoding="o200k_base", # 计算 tokens 个数的本地模型
)

translate(
  llm=llm, # 上一步构造的 llm 对象
  source_path="/path/to/epub/file", # 要翻译的原 EPUB 文件
  translated_path="/path/to/translated/epub/file", # 翻译后的 EPUB 保存路径
  target_language=Language.SIMPLIFIED_CHINESE, # 翻译目标语言,此例为简体中文。
  user_prompt="Le Petit Prince 应该译为“小王子”。", # 用户提示词,指导 AI 翻译 (可选)
)

运行后即可得到保留原版版式的「双语 EPUB」,在 KOReader / Koodo Reader / Apple Books 等阅读器里直接打开即可

实际效果

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions