Sign inSign up

johndope/docx-translator

By johndope

โ€ขUpdated over 1 year ago

๐ŸŒ๐Ÿ“„โœจ Immersive translation of Word docx files

Image
Machine learning & AI
0

434

johndope/docx-translator repository overview

header

Englishโ  ยท Franรงaisโ  ยท Deutschโ  ยท ็ฎ€ไฝ“ไธญๆ–‡โ  ยท ็น้ซ”ไธญๆ–‡โ  ยท ํ•œ๊ตญ์–ดโ  ยท Portuguรชsโ 

Looking for someone to translate this README.

Pure, unadulterated vibe coding powers this entire beast of a project. vibe coding

DocxTranslator is a tool to translate Word documents (.docx) using OpenAI's API. It preserves the original document formatting and adds translations below each paragraph.

PyPI โ  Docker Hub โ  GitHub stars โ  License โ 

โคท If these images don't display, you can view them on Githubโ 

โ โœจ Features

  • ๐Ÿ”„ Translate Word documents (.docx) using OpenAI GPT models
  • ๐ŸŽจ Preserve document formatting and structure
  • ๐ŸŒ Add translations directly below the original text
  • ๐Ÿ’ป Command-line interface for easy integration into scripts
  • ๐ŸŒ Web interface powered by Streamlit
  • ๐Ÿ’พ Translation caching to avoid redundant API calls
  • โšก Parallel processing for faster translation
  • ๐Ÿ”ง Support for custom OpenAI API endpoints

โ ๐Ÿ“ฆ Installation

โ Via Pip
pip install docx-translator
โ Via Docker

You can use the prebuilt Docker image to get started immediately:

# Pull the prebuilt image
docker pull johndope/docx-translator:latest

# Run with your API key
docker run -p 8501:8501 -e OPENAI_API_KEY=your-api-key johndope/docx-translator

โ ๐Ÿ–ฅ๏ธ Command Line Usage

After installation, you can use the dt command to translate documents:

# Basic usage
dt translate document.docx Spanish

# Specify output file
dt translate document.docx French --output translated_document.docx

# Translate specific paragraph styles
dt translate document.docx German --styles "Normal,Heading 1,List Paragraph"

# Use a different model
dt translate document.docx Japanese --model gpt-4o

# Disable caching
dt translate document.docx Chinese --no-cache

# Clear cache for a language before translation
dt translate document.docx Italian --clear-cache

# Process sequentially (instead of in parallel)
dt translate document.docx Russian --sequential

# Show verbose logging
dt translate document.docx Portuguese --verbose
โ ๐Ÿงน Clear Translation Caches
dt clear-caches
โ ๐Ÿš€ Launch Web Interface
dt serve

โ ๐Ÿณ Docker Usage

You can run DocxTranslator using Docker:

# Pull the prebuilt image
docker pull johndope/docx-translator:latest

# Run with your API key
docker run -p 8501:8501 -e OPENAI_API_KEY=your-api-key johndope/docx-translator
โ Option 2: Using docker-compose
# Create a .env file with your OpenAI API key and other settings
echo "OPENAI_API_KEY=your-api-key" > .env

# Build and start the Docker container
docker-compose up -d

# Access the web interface at http://localhost:8501

The Docker setup:

  • ๐Ÿ“‚ Uses the installed package directly via the dt command
  • ๐Ÿ’ฝ Mounts a cache directory for persistent translations
  • ๐Ÿ“ Mounts a data directory for sharing documents with the container

โ ๐Ÿ”‘ Environment Variables

You can set the following environment variables (or use a .env file):

  • OPENAI_API_KEY: Your OpenAI API key
  • OPENAI_BASE_URL: Custom base URL for OpenAI API (optional)
  • OPENAI_MODEL: The model to use (default: gpt-4-turbo)
  • OPENAI_MAX_CONCURRENT: Maximum concurrent requests (default: 5)
  • TARGET_LANGUAGE: Default target language (default: Spanish)
  • DOCX_TRANSLATOR_CACHE_DIR: Custom cache directory

โ ๐Ÿ Python API

You can also use DocxTranslator programmatically:

from pathlib import Path
from docx_translator.translator import setup_openai_client, process_document

# Set up OpenAI client
client = setup_openai_client(api_key="your-api-key")

# Translate document
process_document(
   input_file=Path("document.docx"),
   output_file=Path("translated_document.docx"),
   target_language="Spanish",
   target_styles=["Normal", "Heading 1"],
   openai_client=client,
   use_cache=True,
   parallel=True,
   max_concurrent=5
)

โ ๐ŸŒ Web Interface

DocxTranslator includes a web interface powered by Streamlit. To start it:

dt serve

This will launch a local web server where you can:

  • ๐Ÿ“ค Upload Word documents
  • ๐ŸŽฏ Select which paragraph styles to translate
  • โš™๏ธ Configure OpenAI API settings
  • ๐Ÿš€ Start translations with progress tracking
  • ๐Ÿ“ฅ Download the translated document

โ ๐Ÿ“œ License

MIT

Tag summary

Content type

Image

Digest

sha256:0421176bfโ€ฆ

Size

183.4 MB

Last updated

over 1 year ago

docker pull johndope/docx-translator