WordFlux 🌀
Translate DOCX documents with perfect formatting
WordFlux is a powerful and intelligent tool for translating Microsoft Word documents (.docx) from one language to another while preserving the original formatting, structure, and layout completely.
✨ Key Features
🔧 Comprehensive Translation
- ✅ Regular text paragraphs - Translate while preserving formatting (bold, italic, underline, superscript, subscript)
- ✅ Tables - Translate content in table cells
- ✅ Charts - Translate titles and data labels
- ✅ SmartArt - Translate text in SmartArt diagrams
- ✅ Complex formatting - Preserve all text formatting, colors, fonts
⚡ High Performance
- 🚀 Parallel processing - Use async/await to translate multiple segments simultaneously
- 📦 Smart chunking - Automatically split content to optimize API calls
- 🎯 Concurrent requests - Support up to 100 concurrent requests (configurable)
- 💾 Checkpoint system - Save progress to resume if interrupted
🛡️ Reliable
- 🔄 Retry mechanism - Automatically retry on errors
- 📊 Progress tracking - Track progress with progress bars
- 🎨 Format preservation - Maintain original formatting completely
- 🔍 Error handling - Handle errors intelligently and user-friendly
🚀 Installation
System Requirements
- Python 3.12+
- OpenAI API key
Install from source
# Clone repository
git clone https://github.com/pnnbao97/wordflux.git
cd wordflux
# Install dependencies
pip install -e .
Manual dependency installation
pip install openai>=2.3.0 python-docx>=1.2.0 pyyaml>=6.0.3 tqdm>=4.67.1
⚙️ Configuration
Create a config.yaml file in the root directory:
# OpenAI Configuration
openai_api_key: "sk-your-openai-api-key-here" # Replace with your API key
model: "gpt-4o-mini" # Can use gpt-4, gpt-3.5-turbo, etc.
# Translation Settings
source_lang: "English"
target_lang: "Vietnamese"
# Performance Settings
max_concurrent: 100 # Maximum concurrent requests
max_chunk_size: 5000 # Maximum chunk size (characters)
Supported OpenAI Models
gpt-4o-mini(default, cost-effective)gpt-4ogpt-4gpt-3.5-turbo- And other OpenAI models
📖 Usage
1. Command Line Usage
# Translate DOCX file
python main.py input_file.docx
# Specify output directory
python main.py input_file.docx --output_dir ./my_output
# Concrete example
python main.py document.docx --output_dir ./translated_docs
2. Use as Python Module
from wordflux import DocxTranslator
# Initialize translator
translator = DocxTranslator(
input_file="document.docx",
output_dir="output",
openai_api_key="your-api-key",
model="gpt-4o-mini",
source_lang="English",
target_lang="Vietnamese",
max_chunk_size=5000,
max_concurrent=100
)
# Perform translation
translator.translate()
# Get translated file path
output_path = translator.get_output_path()
print(f"Translated file: {output_path}")
3. Step-by-step Usage
from wordflux import DocxTranslator
translator = DocxTranslator("document.docx", "output", "your-api-key")
# Step 1: Extract content
translator.extract()
# Step 2: Translate content
translator.translator.translate()
# Step 3: Inject translations into file
translator.inject()
🔧 Advanced Configuration
Performance Tuning
# config.yaml
max_concurrent: 50 # Reduce if encountering rate limit errors
max_chunk_size: 3000 # Reduce for complex documents
Change Languages
source_lang: "English"
target_lang: "French" # Or "Spanish", "German", "Chinese", etc.
Use Different Models
model: "gpt-4o" # More powerful model, more expensive
# or
model: "gpt-3.5-turbo" # Faster model, cheaper
📁 Project Structure
wordflux/
├── 📄 main.py # Entry point
├── ⚙️ config.yaml # Configuration
├── 📋 pyproject.toml # Project metadata
├── 📖 README.md # This documentation
├── 🗂️ output/ # Output directory for translated files
│ ├── document_translated.docx
│ └── document_checkpoint.json
└── 📦 wordflux/ # Main package
├── 📄 __init__.py
├── 🔧 docxtranslator.py # Main class
├── 📄 document/ # Data models
│ └── document.py
├── 🔨 worker/ # Core workers
│ ├── extractor.py # Extract content
│ ├── translator.py # Translate content
│ └── injector.py # Inject translations
└── 🛠️ utils/ # Utilities
├── decorator.py # Decorators (timer, retry, etc.)
├── is_numeric.py # Helper functions
├── openai_client.py # OpenAI client manager
├── prompt_builder.py # Build prompts
└── spinner.py # Loading spinner
🎯 Usage Examples
Simple Document Translation
# Translate document.docx from English to Vietnamese
python main.py document.docx
🚨 Error Handling
API Key Error
❌ Translation failed: OpenAI API key not found in config
Solution: Check config.yaml file and ensure API key is correct.
Rate Limit Error
❌ Translation failed: Rate limit exceeded
Solution: Reduce max_concurrent in config.yaml from 100 to 50 or 25.
File Not Found Error
❌ Translation failed: [Errno 2] No such file or directory: 'document.docx'
Solution: Check input file path.
💡 Tips and Tricks
1. Cost Optimization
- Use
gpt-4o-miniinstead ofgpt-4ofor simple documents - Adjust
max_chunk_sizeaccording to content
2. Speed Optimization
- Increase
max_concurrentif you have high API quota - Use SSD for temporary file storage
3. Large Document Handling
- Split large documents into smaller files
- Use checkpoint system to resume if interrupted
4. Quality Control
- Always review translations before use
- Adjust prompts if necessary
🤝 Contributing
We welcome contributions! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
📄 License
This project is distributed under the MIT License. See the LICENSE file for more information.
👨💻 Author
Pham Nguyen Ngoc Bao
- 📧 Email: pnnbao@gmail.com
- 🐙 GitHub: @pnnbao97
- 📘 Facebook: pnnbao
🙏 Acknowledgments
- OpenAI API for powerful translation capabilities
- python-docx library for DOCX file processing
- Python community for supporting libraries
📞 Support
If you encounter issues or have questions:
- 📖 Read this documentation carefully
- 🔍 Check Issues
- 🆕 Create a new issue if no solution exists
- 📧 Contact directly: pnnbao@gmail.com
WordFlux - Smart document translation with perfect formatting preservation! 🌀✨
Metadata
Release files for wordflux 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wordflux-0.1.0.tar.gz | 42.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wordflux-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.7 kB
Release files / wordflux-0.1.0.tar.gz
| Download URL | wordflux-0.1.0.tar.gz |
|---|---|
| Size | 42.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62adcc9db0a38838c0517a3c4c0768d9f01fc0a42a7504e1d479f6ec2a55d0b1
|
|
BLAKE2b-256 checksum How to use checksums |
5193edcbcf31a0e1ed9a51292e3671c643f0c94e0c87342e3bf4c08022f7b659
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.0
|
Release files / wordflux-0.1.0-py3-none-any.whl
| Download URL | wordflux-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53a0a566ae2b6da61ab8682bf763dc6d20c0b373fa002a56980096f841b88045
|
|
BLAKE2b-256 checksum How to use checksums |
439ac1844ac67c4fc87e51217f7dee426c76b84845f60137c32e210aa57aea5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.0
|