6.3 KiB
6.3 KiB
🚀 Quick Start Guide - Document Translation API
Step-by-Step Setup (5 Minutes)
1️⃣ Open PowerShell in Project Directory
cd d:\Translate
2️⃣ Run the Startup Script
.\start.ps1
This will automatically:
- Create a virtual environment
- Install all dependencies
- Create necessary directories
- Start the API server
3️⃣ Test the API
Open another PowerShell window and run:
python test_api.py
Or visit in your browser:
- API Documentation: http://localhost:8000/docs
- API Status: http://localhost:8000/health
📤 Translate Your First Document
Using cURL (PowerShell)
$file = Get-Item "your_document.xlsx"
Invoke-RestMethod -Uri "http://localhost:8000/translate" `
-Method Post `
-Form @{
file = $file
target_language = "es"
} `
-OutFile "translated_document.xlsx"
Using Python
import requests
with open('document.docx', 'rb') as f:
response = requests.post(
'http://localhost:8000/translate',
files={'file': f},
data={'target_language': 'fr'}
)
with open('translated_document.docx', 'wb') as out:
out.write(response.content)
Using the Interactive API Docs
- Go to http://localhost:8000/docs
- Click on POST /translate
- Click "Try it out"
- Upload your file
- Enter target language (e.g.,
esfor Spanish) - Click "Execute"
- Download the translated file
🌍 Supported Languages
Use these language codes in the target_language parameter:
| Code | Language | Code | Language |
|---|---|---|---|
es |
Spanish | fr |
French |
de |
German | it |
Italian |
pt |
Portuguese | ru |
Russian |
zh |
Chinese | ja |
Japanese |
ko |
Korean | ar |
Arabic |
hi |
Hindi | nl |
Dutch |
Full list: http://localhost:8000/languages
📋 Supported File Types
| Format | Extension | What's Preserved |
|---|---|---|
| Excel | .xlsx |
Formulas, merged cells, colors, borders, images |
| Word | .docx |
Styles, tables, headers/footers, images |
| PowerPoint | .pptx |
Layouts, animations, transitions, media |
🔧 Configuration
Edit .env file to customize:
# Translation service: google (free) or deepl (requires API key)
TRANSLATION_SERVICE=google
# For DeepL (premium translation)
DEEPL_API_KEY=your_api_key_here
# Maximum file size in MB
MAX_FILE_SIZE_MB=50
⚠️ Troubleshooting
Issue: "Virtual environment activation failed"
Solution:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Issue: "Module not found"
Solution:
.\venv\Scripts\Activate.ps1
pip install -r requirements.txt
Issue: "Port 8000 already in use"
Solution:
Edit main.py line 307:
uvicorn.run(app, host="0.0.0.0", port=8001, reload=True)
Issue: "Translation quality is poor"
Solution:
- Get a DeepL API key from https://www.deepl.com/pro-api
- Update
.env:TRANSLATION_SERVICE=deepl DEEPL_API_KEY=your_key_here
📦 Project Structure
Translate/
├── main.py # FastAPI application (START HERE)
├── config.py # Configuration management
├── start.ps1 # Startup script (RUN THIS FIRST)
├── test_api.py # Testing script
│
├── services/ # Translation service layer
│ ├── __init__.py
│ └── translation_service.py # Pluggable translation backend
│
├── translators/ # Document-specific translators
│ ├── __init__.py
│ ├── excel_translator.py # Excel (.xlsx) handler
│ ├── word_translator.py # Word (.docx) handler
│ ├── pptx_translator.py # PowerPoint (.pptx) handler
│ └── excel_advanced.py # Advanced Excel features
│
├── utils/ # Utility modules
│ ├── __init__.py
│ ├── file_handler.py # File operations
│ └── exceptions.py # Error handling
│
├── requirements.txt # Python dependencies
├── README.md # Full documentation
├── ARCHITECTURE.md # Technical architecture
└── DEPLOYMENT.md # Production deployment guide
🎯 Next Steps
For Development
- ✅ Run
start.ps1to start the server - ✅ Test with
test_api.py - ✅ Try translating sample documents
- Read
ARCHITECTURE.mdfor technical details
For Production
- Read
DEPLOYMENT.mdfor production setup - Configure environment variables
- Set up Docker container
- Enable authentication and rate limiting
For MCP Integration
- Install MCP requirements:
pip install -r requirements-mcp.txt - Review
mcp_server_example.py - Configure MCP server in your AI assistant
📞 API Endpoints Reference
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | API information |
/health |
GET | Health check |
/languages |
GET | Supported languages |
/translate |
POST | Translate single document |
/translate-batch |
POST | Translate multiple documents |
/download/{filename} |
GET | Download translated file |
/cleanup/{filename} |
DELETE | Delete translated file |
💡 Tips & Best Practices
- File Size: Keep files under 50MB for best performance
- Format Preservation: More complex formatting = longer processing time
- Language Codes: Use ISO 639-1 codes (2 letters)
- Cleanup: Enable cleanup to save disk space
- Batch Translation: Use batch endpoint for multiple files
🌟 Features Highlights
✨ Zero Data Loss: All formatting, colors, styles preserved ✨ Formula Intelligence: Translates text in formulas, keeps logic ✨ Image Preservation: Embedded media stays in exact positions ✨ Smart Translation: Auto-detects source language ✨ MCP Ready: Designed for AI assistant integration
📄 License
MIT License - Free to use and modify
🤝 Support
- Documentation: See
README.mdfor full details - Issues: Open an issue on the repository
- Architecture: Read
ARCHITECTURE.mdfor technical depth
Ready to translate? Run .\start.ps1 and visit http://localhost:8000/docs 🚀