Skip to content

quickly translate epub books into a bilingual book using Anthropic LLMs

License

Notifications You must be signed in to change notification settings

nguyenvanduocit/epubtrans

Repository files navigation

Epub Translator

Open In Colab

This project aims to quickly translate epub books into bilingual book. It's designed to maintain the original text format while providing a rough translation.

Watch the tutorial video (Vietnamese)

Table of Contents

Quick Start

  1. Install Epub Translator (see Installation)
  2. Set up your ANTHROPIC_KEY:
    export ANTHROPIC_KEY=your_anthropic_key
  3. Translate a book:
    epubtrans unpack /path/to/book.epub
    epubtrans clean /path/to/unpacked-epub
    epubtrans mark /path/to/unpacked-epub
    epubtrans translate /path/to/unpacked-epub --source English --target Vietnamese
    epubtrans pack /path/to/unpacked

Installation

Prerequisites

  • Windows: PowerShell 5.1 or later
  • Linux/macOS: Bash shell
  • All systems: Internet connection

Windows

  1. Open PowerShell as Administrator and run:
$ErrorActionPreference = "Stop"
$version = (Invoke-RestMethod "https://api.github.com/repos/nguyenvanduocit/epubtrans/releases/latest").tag_name
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
$url = "https://github.com/nguyenvanduocit/epubtrans/releases/download/${version}/epubtrans_${version.Substring(1)}_windows_${arch}.tar.gz"
Invoke-WebRequest -Uri $url -OutFile "epubtrans.tar.gz"
tar -xzf epubtrans.tar.gz
Move-Item -Force epubtrans.exe "C:\Windows\System32\"
Remove-Item epubtrans.tar.gz
Write-Host "epubtrans $version has been installed successfully!"

Linux and macOS

Open a terminal and run:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/nguyenvanduocit/epubtrans/main/scripts/install_unix.sh)"

Verify Installation

After installation, verify by running:

epubtrans --version

Usage

Available Commands

Usage:
  epubtrans [flags]
  epubtrans [command]

Available Commands:
  clean       Clean the html files
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  mark        Mark content in EPUB files
  pack        Zip files in a directory
  serve       Serve the content of an unpacked EPUB as a web server
  styling     Style the content of an unpacked EPUB
  translate   Translate the content of an unpacked EPUB
  unpack      Unpack a book
  upgrade     Self update the tool

Flags:
  -h, --help      help for epubtrans
  -v, --version   version for epubtrans

Step-by-step Guide

  1. Configure environment:

    export ANTHROPIC_KEY=your_anthropic_key

    Note: You need to obtain an ANTHROPIC_KEY from Anthropic's website to use their translation API.

  2. Unpack the epub file:

    epubtrans unpack /path/to/file.epub
  3. Clean up HTML files:

    epubtrans clean /path/to/unpacked-epub
  4. Mark content for translation:

    epubtrans mark /path/to/unpacked-epub
  5. Translate marked content:

    epubtrans translate /path/to/unpacked-epub --source English --target Vietnamese
  6. (Optional) Apply styling:

    epubtrans styling /path/to/unpacked --hide "source|target"

the command also make original text to be faded out a little bit, so that the translated text can be more visible.

  1. Package into a bilingual book:
    epubtrans pack /path/to/unpacked

Web Serving

To serve the book on the web:

epubtrans serve /path/to/unpacked

Important endpoints:

Editing Translations

When accessing the book via the serve command, the translated content is editable. After editing, the content is automatically saved when you move the mouse away.

To apply changes, run the pack command again.

Watch the editing tutorial video

Contributing

We welcome contributions to the Epub Translator project! Here's how you can help:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Make your changes and commit them
  4. Push to your fork and submit a pull request

Please ensure your code adheres to the project's coding standards and include tests for new features.

Limitations and Known Issues

  • The quality of translation depends on the Anthropic API and may not be perfect for all types of content.
  • Large books may take a considerable amount of time to translate.

For any issues or feature requests, please open an issue on the GitHub repository.