Skip to main content

Translate the epub book using LLM. The translated book will retain the original text and list the translated text side by side with the original text.

Project description

EPUB Translator

pip install epub-translator python versions

Open in OOMOL Studio

English | 中文

Introduction

epub-translator uses AI big models to automatically translate EPUB e-books, and retains 100% of the original book's format, illustrations, catalog and layout, while generating bilingual comparison versions for easy language learning or international sharing.

Whether you are a developer, language learner, or e-book lover, epub-translator can help you easily overcome language barriers.

  • Multi-language translation: Supports translation between mainstream languages ​​such as English, Chinese, Japanese, Spanish, French, and German.
  • Bilingual comparison: Generates bilingual EPUBs with top-down comparisons for easy comparison and learning.
  • Insert prompt words: Guide AI translation, such as glossary, character name list, etc.
  • Optional AI model: Supports mainstream big models such as DeepSeek and ChatGPT.
  • High-performance parallelism: AI requests multiple concurrent channels to quickly translate the entire book.

Environment

You can call EPUB Translator directly as a library, or use OOMOL Studio to run it directly.

Run with OOMOL Studio

OOMOL uses container technology to directly package the dependencies required by EPUB Translator, and it is ready to use out of the box.

Call directly as a library

You can also write python code directly and call it as a library. At this time, you need python 3.10 or higher (3.10.16 is recommended).

pip install epub-translator

Quick start

First, construct the LLM object that calls the AI ​​Large Language Model.

from epub_translator import LLM

llm = LLM(
  key="<LLM-API-KEY>", # LLM's API key
  url="https://api.deepseek.com", # LLM's base URL
  model="deepseek-chat", # LLM's model name
  token_encoding="o200k_base", # Local model for calculating the number of tokens
)

Then, you can call the translate method to translate.

from epub_translator import translate, Language

translate(
  llm=llm, # llm object constructed in the previous step
  source_path="/path/to/epub/file", # Original EPUB file to be translated
  translated_path="/path/to/translated/epub/file", # Path to save the translated EPUB
  target_language=Language.ENGLISH, # Target language for translation, in this case English.
)

After calling this method, the translation can be inserted under the original text while retaining the EPUB format.

Function

Save translation progress

Calling translate to translate the entire EPUB e-book takes a long time, and this process may be interrupted for various reasons. For example, when calling LLM, an error is reported and the process is interrupted due to network reasons, or the user can't wait and manually interrupts the process.

EPUB Translator can cache the translated content as a local file, so that when translating the same book, the translation progress can be saved and the progress can be restored from the last translation interruption.

Just configure the working_path field when calling translate and specify a path to cache the files generated by the translation. The next time it is started, EPUB Translator will try to read the translation progress from this path in advance.

translate(
  ..., # other parameters
  working_path="/path/to/cache/translating/files",
)

Please note that each call to the translate method will write a cache file to the folder where the workspace_path is located. This will cause the folder to grow larger and larger. You need to handle it yourself, for example, automatically clear the folder after the translation is successful.

Monitor translation progress

When calling translate, pass a callback function through report_progress, and receive a float type parameter representing the progress from 0.0 to 1.0, so that the translation progress of the whole book can be monitored.

from tqdm import tqdm
from epub_translator import translate

with tqdm(total=1.0, desc="Translating") as bar:
  def refresh_progress(progress: float) -> None:
    bar.n = progress
    bar.refresh()

  translate(
    ..., # other parameters
    report_progress=refresh_progress,
  )

Insert prompt words

Insert prompt words to guide the AI ​​language model on how to translate. For example, you can insert a glossary so that AI can unify the terms when translating. Just add the user_prompt field when calling translate.

translate(
  ..., # other parameters
  user_prompt='Le Petit Prince should be translated as "Little Prince".',
)

Large Language Model Parameters

There are more configuration options when building the LLM object.

llm = LLM(
  key="<LLM-API-KEY>", # LLM's API key
  url="https://api.deepseek.com", # LLM's base URL
  model="deepseek-chat", # LLM's model name
  token_encoding="o200k_base", # Local model for calculating the number of tokens
  timeout=60.0, # Request timeout (in seconds)
  top_p=0.6, # Creativity
  temperature=0.85, # Temperature
  retry_times=5, # Retry times. If the request still fails after this number, an error will be reported
  retry_interval_seconds=6.0, # Retry interval (in seconds)
)

Related open source libraries

PDF Craft can convert PDF files into various other formats. This project will focus on the processing of PDF files of scanned books. Use this library with the scanned PDF books to convert and translate them. For more information, please refer to Video: Convert scanned PDF books to EPUB format and translate them into bilingual books.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epub_translator-0.0.7.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

epub_translator-0.0.7-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file epub_translator-0.0.7.tar.gz.

File metadata

  • Download URL: epub_translator-0.0.7.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.4 Darwin/24.5.0

File hashes

Hashes for epub_translator-0.0.7.tar.gz
Algorithm Hash digest
SHA256 cdd415ca61a7829e56661695ed585e69dc79c29ea2b29f93a66d915a398a5b88
MD5 2fa90ee44814d2871614a9223e7ce080
BLAKE2b-256 af83d49faf1bafe3206b47388aec91e6fd3679a5f5c62dfe52cc0f850ccb9921

See more details on using hashes here.

File details

Details for the file epub_translator-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: epub_translator-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.4 Darwin/24.5.0

File hashes

Hashes for epub_translator-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4f1ab01649589940fcb6f68e5ddfd2778e127db03940fe73541acb85c2d286af
MD5 73c2bd1865c8045a07aa9adb2e50b8d0
BLAKE2b-256 3c3c1d8167e422bb985c6a741eb5713725e902646810389da8263bd458a32847

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page