/epubtrans

quickly translate epub books into a bilingual book using Anthropic LLMs

Primary LanguageGoOtherNOASSERTION

Epub Translator

This project aims to quickly translate epub books into Vietnamese. It packages the result as a bilingual book.

You may want to watch the tutorial video - Vietnamese.

Acceptance Criteria

  • Only need to create a rough translation.
  • Maintain the format of the original text.

Installation

  1. Install Go. You can download it from here.
  2. Install the tool
go install github.com/nguyenvanduocit/epubtrans@latest

Usage

To manage the translation content, we need to mark the content that needs to be translated, then translate and mark the translated content. We divide it into 3 commands.

  1. unpack to extract the epub file.
  2. mark to mark the content that needs to be translated.
  3. clean to clean up erroneous content.
  4. translate to translate the marked content.
  5. pack to package it into a bilingual book.
  6. serve to serve the whole book as a static webserver.

Step-by-step

All commands take the path to the epub file to be translated as the first parameter.

  1. Config env
export ANTHROPIC_KEY=your_anthropic_key
  1. Unpack the epub file.
epubtrans unpack /path/to/file.epub
  1. Clean up html files.
epubtrans clean /path/to/unpacked
  1. Mark the content that needs to be translated.
epubtrans mark /path/to/unpacked

At this point, you will see a folder with the name of the epub, containing the html files of the epub. The content of these html files has been marked.

  1. Translate the marked content.
epubtrans translate /path/to/unpacked

This process will take some time. At the end of the process, you will have html files with the translated content.

  1. Apply style to the translated content.

The step is optional. Only when you want to apply some style to the translated content.

epubtrans styling /path/to/unpacked --hide "source|target"
  1. Package it into a bilingual book.
epubtrans pack /path/to/unpacked

At this point, you will have a repacked epub file with bilingual content.

How to serve the book on web?

You can run the command serve. then the console will show you the address to access the book.

There are some important endpoints:

How to edit the translation?

When accessing the book via serve command, you can see that the translated content is editable. After edit and leave the mouse, the content will be saved automatically.

After that, you just need to run the pack command to package the book again.

Snippets

How to hide all English content?

You need to add the following CSS to every html file or css file:

[data-content-id] {
    display: none !important;
}

How to make original content less visible?

You need to add the following CSS to every html file or css file:

[data-content-id] {
    opacity: 0.8;
}