English · Français · Deutsch · 简体中文 · 繁體中文 · 한국어 · Português
Looking for someone to translate this README.
Pure, unadulterated vibe coding powers this entire beast of a project.
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.
⤷ 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:
Option 1: Using prebuilt image (recommended)
# 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
dtcommand - 💽 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 keyOPENAI_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
Release files for docx-translator 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| docx_translator-0.2.1.tar.gz | 23.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| docx_translator-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.3 kB
Release files / docx_translator-0.2.1.tar.gz
| Download URL | docx_translator-0.2.1.tar.gz |
|---|---|
| Size | 23.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd191fa88bcabe6286613623cac49238bcdb706ae15ff9aac810e776b3d99dcf
|
|
BLAKE2b-256 checksum How to use checksums |
e15c046a53cacbf31c660759e2955ae905c60d6cd57aea2d8b19bf60ea16bd38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.12
|
Release files / docx_translator-0.2.1-py3-none-any.whl
| Download URL | docx_translator-0.2.1-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd72137d5b0f0959479b983081ab8fc1c34311805213b1cc65a02f6103009ee6
|
|
BLAKE2b-256 checksum How to use checksums |
4230f08348b353591ee67fe6f4890c71e2b317fc9285f2991a8f9d284fd5ce36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.12
|