Skip to main content

Translate DOCX files using OpenAI-compatible models

Project description

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.

✨ 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

pip install 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:

# 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

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

docx_translator-0.1.9.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

docx_translator-0.1.9-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file docx_translator-0.1.9.tar.gz.

File metadata

  • Download URL: docx_translator-0.1.9.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.12

File hashes

Hashes for docx_translator-0.1.9.tar.gz
Algorithm Hash digest
SHA256 5ce62df43bd3b42da137ef4d81b297b2917e7eb5ea3293c0044fe3c878ac5752
MD5 9b3dad67cb4002e463a22f6b4fbe0e71
BLAKE2b-256 9284b52a20c1b17f03403257f6eb80496620f63b4ceaae30dd395452ad1bff47

See more details on using hashes here.

File details

Details for the file docx_translator-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for docx_translator-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7a8b0bc52043913969ed63fd4f1a6a87f3bd1e09804a579609ca9aa536d0afa8
MD5 b54e481369e1b4b10ef42a1443002a6b
BLAKE2b-256 48963717fbfda9387f3e6b07db6133a5dbe77be706421a79700d9d5ab7b8b2be

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