|
4 | 4 |  |
5 | 5 |  |
6 | 6 |
|
7 | | -A robust tool for translating gettext (.po) files using AI models from multiple providers (OpenAI, Azure OpenAI, Anthropic/Claude, and DeepSeek). It supports both bulk and individual translations, handles fuzzy entries, and can infer target languages based on folder structures. Available as a Python package and Docker container with support for Python 3.8-3.12. |
| 7 | +**Translate gettext (.po) files using AI models.** Supports OpenAI, Azure OpenAI, Anthropic/Claude, and DeepSeek with automatic AI translation tagging. |
8 | 8 |
|
9 | | -## What is GPT-PO Translator? |
10 | | - |
11 | | -This tool helps you translate gettext (.po) files using AI models. It's perfect for developers who need to localize their applications quickly and accurately. |
12 | | - |
13 | | -### Key Features |
14 | | - |
15 | | -- **Multiple AI providers** - OpenAI, Azure OpenAI, Anthropic/Claude, and DeepSeek |
16 | | -- **Flexible translation modes** - Bulk or entry-by-entry processing |
17 | | -- **Smart language handling** - Auto-detects target languages from folder structure |
18 | | -- **AI translation tracking** - Automatically tags AI-generated translations with comments |
19 | | -- **Production-ready** - Includes retry logic, validation, and detailed logging |
20 | | -- **Easy deployment** - Available as a Python package or Docker container |
21 | | -- **Cross-version support** - Works with Python 3.8-3.12 |
22 | | - |
23 | | -## Getting Started |
24 | | - |
25 | | -### Quick Install |
| 9 | +## 🚀 Quick Start |
26 | 10 |
|
27 | 11 | ```bash |
| 12 | +# Install |
28 | 13 | pip install gpt-po-translator |
29 | | -``` |
30 | | - |
31 | | -### Basic Usage |
32 | | - |
33 | | -To translate the `po` files for the German and French languages found in the `locales` folder, using OpenAI: |
34 | 14 |
|
35 | | -```bash |
36 | | -# Set up your API key |
| 15 | +# Set API key |
37 | 16 | export OPENAI_API_KEY='your_api_key_here' |
38 | 17 |
|
39 | | -# Translate files to German and French |
| 18 | +# Translate to German and French |
40 | 19 | gpt-po-translator --folder ./locales --lang de,fr --bulk |
41 | 20 | ``` |
42 | 21 |
|
43 | | -## Installation Options |
| 22 | +## ✨ Key Features |
44 | 23 |
|
45 | | -### PyPI (Recommended) |
| 24 | +- **Multiple AI providers** - OpenAI, Azure OpenAI, Anthropic/Claude, DeepSeek |
| 25 | +- **AI translation tracking** - Auto-tags AI-generated translations with `#. AI-generated` comments |
| 26 | +- **Bulk processing** - Efficient batch translation for large files |
| 27 | +- **Smart language detection** - Auto-detects target languages from folder structure |
| 28 | +- **Fuzzy entry handling** - Translates and fixes fuzzy entries properly |
| 29 | +- **Docker ready** - Available as container for easy deployment |
46 | 30 |
|
| 31 | +## 📦 Installation |
| 32 | + |
| 33 | +### PyPI (Recommended) |
47 | 34 | ```bash |
48 | 35 | pip install gpt-po-translator |
49 | 36 | ``` |
50 | 37 |
|
51 | | -### Manual Installation |
| 38 | +### Docker |
| 39 | +```bash |
| 40 | +docker pull ghcr.io/pescheckit/python-gpt-po:latest |
| 41 | +``` |
52 | 42 |
|
| 43 | +### Manual |
53 | 44 | ```bash |
54 | 45 | git clone https://github.com/pescheckit/python-gpt-po.git |
55 | 46 | cd python-gpt-po |
56 | | -python3 -m venv .venv |
57 | | -source .venv/bin/activate |
58 | | -pip install -r requirements.txt |
| 47 | +pip install -e . |
59 | 48 | ``` |
60 | 49 |
|
61 | | -### Docker |
62 | | - |
63 | | -```bash |
64 | | -# Pull the latest image |
65 | | -docker pull ghcr.io/pescheckit/python-gpt-po:latest |
| 50 | +## 🔧 Setup |
66 | 51 |
|
67 | | -# Run with your local directory mounted |
68 | | -docker run -v $(pwd):/data \ |
69 | | - -e OPENAI_API_KEY="your_key" \ |
70 | | - ghcr.io/pescheckit/python-gpt-po:latest \ |
71 | | - --folder /data --lang fr,de --bulk |
| 52 | +### API Keys |
72 | 53 |
|
73 | | -# Or with Azure OpenAI |
74 | | -docker run -v $(pwd):/data \ |
75 | | - -e AZURE_OPENAI_API_KEY="your_key" \ |
76 | | - -e AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/" \ |
77 | | - -e AZURE_OPENAI_API_VERSION="2024-02-01" \ |
78 | | - ghcr.io/pescheckit/python-gpt-po:latest \ |
79 | | - --provider azure_openai --folder /data --lang fr,de --bulk |
80 | | -``` |
| 54 | +Choose your AI provider and set the corresponding API key: |
81 | 55 |
|
82 | | -## Setting Up API Keys |
| 56 | +```bash |
| 57 | +# OpenAI |
| 58 | +export OPENAI_API_KEY='your_key' |
83 | 59 |
|
84 | | -### Option 1: Environment Variables |
| 60 | +# Anthropic/Claude |
| 61 | +export ANTHROPIC_API_KEY='your_key' |
85 | 62 |
|
86 | | -```bash |
87 | | -export OPENAI_API_KEY='your_api_key_here' |
88 | | -# Or for other providers: |
89 | | -export ANTHROPIC_API_KEY='your_api_key_here' |
90 | | -export DEEPSEEK_API_KEY='your_api_key_here' |
| 63 | +# DeepSeek |
| 64 | +export DEEPSEEK_API_KEY='your_key' |
91 | 65 |
|
92 | | -# For Azure OpenAI: |
93 | | -export AZURE_OPENAI_API_KEY='your_api_key_here' |
| 66 | +# Azure OpenAI |
| 67 | +export AZURE_OPENAI_API_KEY='your_key' |
94 | 68 | export AZURE_OPENAI_ENDPOINT='https://your-resource.openai.azure.com/' |
95 | 69 | export AZURE_OPENAI_API_VERSION='2024-02-01' |
96 | 70 | ``` |
97 | 71 |
|
98 | | -### Option 2: Command Line |
99 | | - |
100 | | -```bash |
101 | | -gpt-po-translator --api_key 'your_api_key_here' [other options] |
102 | | -``` |
103 | | - |
104 | | -## Usage Examples |
| 72 | +## 💡 Usage Examples |
105 | 73 |
|
106 | 74 | ### Basic Translation |
107 | | - |
108 | 75 | ```bash |
109 | 76 | # Translate to German |
110 | 77 | gpt-po-translator --folder ./locales --lang de |
111 | | -``` |
112 | 78 |
|
113 | | -### Bulk Translation with Language Detection |
114 | | - |
115 | | -```bash |
116 | | -# Translate based on folder structure with custom batch size |
117 | | -gpt-po-translator --folder ./locales --lang de,fr --bulk --bulksize 40 --folder-language |
| 79 | +# Multiple languages |
| 80 | +gpt-po-translator --folder ./locales --lang de,fr,es --bulk |
118 | 81 | ``` |
119 | 82 |
|
120 | | -### Using Different AI Providers |
121 | | - |
| 83 | +### Different AI Providers |
122 | 84 | ```bash |
123 | | -# Use Claude models from Anthropic |
| 85 | +# Use Claude (Anthropic) |
124 | 86 | gpt-po-translator --provider anthropic --folder ./locales --lang de |
125 | 87 |
|
126 | | -# Use DeepSeek models |
| 88 | +# Use DeepSeek |
127 | 89 | gpt-po-translator --provider deepseek --folder ./locales --lang de |
128 | 90 |
|
129 | 91 | # Use Azure OpenAI |
130 | | -gpt-po-translator --provider azure_openai \ |
131 | | - --azure-openai-endpoint https://your-resource.openai.azure.com/ \ |
132 | | - --azure-openai-api-version 2024-02-01 \ |
133 | | - --folder ./locales --lang de |
134 | | - |
135 | | -# List available models for different providers |
136 | | -gpt-po-translator --provider openai --list-models |
137 | | -gpt-po-translator --provider azure_openai \ |
138 | | - --azure-openai-endpoint https://your-resource.openai.azure.com/ \ |
139 | | - --azure-openai-api-version 2024-02-01 \ |
140 | | - --list-models |
| 92 | +gpt-po-translator --provider azure_openai --folder ./locales --lang de |
141 | 93 | ``` |
142 | 94 |
|
143 | | -### AI Translation Tracking |
| 95 | +### Docker Usage |
| 96 | +```bash |
| 97 | +# Basic usage |
| 98 | +docker run -v $(pwd):/data \ |
| 99 | + -e OPENAI_API_KEY="your_key" \ |
| 100 | + ghcr.io/pescheckit/python-gpt-po:latest \ |
| 101 | + --folder /data --lang de,fr --bulk |
| 102 | + |
| 103 | +# With Azure OpenAI |
| 104 | +docker run -v $(pwd):/data \ |
| 105 | + -e AZURE_OPENAI_API_KEY="your_key" \ |
| 106 | + -e AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/" \ |
| 107 | + -e AZURE_OPENAI_API_VERSION="2024-02-01" \ |
| 108 | + ghcr.io/pescheckit/python-gpt-po:latest \ |
| 109 | + --provider azure_openai --folder /data --lang de |
| 110 | +``` |
144 | 111 |
|
145 | | -**By default, all AI-generated translations are automatically marked with comments** for easy tracking and compliance: |
| 112 | +## 🏷️ AI Translation Tracking |
146 | 113 |
|
147 | | -```bash |
148 | | -# Default behavior - AI translations are tagged with comments |
149 | | -gpt-po-translator --folder ./locales --lang de |
| 114 | +**All AI translations are automatically tagged** for transparency and compliance: |
150 | 115 |
|
151 | | -# Result in PO file: |
| 116 | +```po |
152 | 117 | #. AI-generated |
153 | 118 | msgid "Hello" |
154 | 119 | msgstr "Hallo" |
155 | | - |
156 | | -# To disable AI tagging (not recommended) |
157 | | -gpt-po-translator --folder ./locales --lang de --no-ai-comment |
158 | 120 | ``` |
159 | 121 |
|
160 | 122 | This helps you: |
161 | | -- Identify which translations were made by AI vs human translators |
162 | | -- Track incremental changes when new AI translations are added |
163 | | -- Comply with requirements to identify AI-generated content |
| 123 | +- Track which translations are AI vs human-generated |
| 124 | +- Comply with AI content disclosure requirements |
| 125 | +- Manage incremental translation workflows |
164 | 126 |
|
165 | | -**Note:** Django's `makemessages` removes these comments when updating PO files, but translations are preserved. Re-run the translator after `makemessages` to restore AI tagging. |
| 127 | +**Note:** Django's `makemessages` removes these comments but preserves translations. Re-run the translator after `makemessages` to restore tags. |
166 | 128 |
|
167 | | -## Command Reference |
| 129 | +## 📚 Command Reference |
168 | 130 |
|
169 | 131 | | Option | Description | |
170 | 132 | |--------|-------------| |
171 | | -| `--folder` | Path to your .po files | |
172 | | -| `--lang` | Target language codes (comma-separated, e.g., `de,fr`) | |
173 | | -| `--detail-lang` | Full language names (e.g., `"German,French"`) | |
174 | | -| `--fuzzy` | Remove fuzzy entries before translating (DEPRECATED - use `--fix-fuzzy`) | |
175 | | -| `--fix-fuzzy` | Translate and fix fuzzy entries properly (recommended) | |
176 | | -| `--bulk` | Enable batch translation (recommended for large files) | |
| 133 | +| `--folder` | Path to .po files | |
| 134 | +| `--lang` | Target languages (e.g., `de,fr,es`) | |
| 135 | +| `--provider` | AI provider: `openai`, `azure_openai`, `anthropic`, `deepseek` | |
| 136 | +| `--bulk` | Enable batch translation (recommended) | |
177 | 137 | | `--bulksize` | Entries per batch (default: 50) | |
178 | | -| `--model` | Specific AI model to use | |
179 | | -| `--provider` | AI provider: `openai`, `azure_openai`, `anthropic`, or `deepseek` | |
180 | | -| `--list-models` | Show available models for selected provider | |
181 | | -| `--api_key` | Your API key | |
182 | | -| `--folder-language` | Auto-detect languages from folder structure | |
183 | | -| `--no-ai-comment` | Disable AI-generated comment tagging (enabled by default) | |
| 138 | +| `--model` | Specific model to use | |
| 139 | +| `--list-models` | Show available models | |
| 140 | +| `--fix-fuzzy` | Translate fuzzy entries | |
| 141 | +| `--folder-language` | Auto-detect languages from folders | |
| 142 | +| `--no-ai-comment` | Disable AI tagging | |
184 | 143 |
|
185 | | -## Advanced Docker Usage |
186 | | - |
187 | | -### Specific Python Versions |
| 144 | +## 🛠️ Development |
188 | 145 |
|
| 146 | +### Build Docker Locally |
189 | 147 | ```bash |
190 | | -# Python 3.11 (default) |
191 | | -docker pull ghcr.io/pescheckit/python-gpt-po:latest |
192 | | - |
193 | | -# Python 3.12 |
194 | | -docker pull ghcr.io/pescheckit/python-gpt-po:latest-py3.12 |
195 | | - |
196 | | -# Specific version |
197 | | -docker pull ghcr.io/pescheckit/python-gpt-po:0.3.0 |
| 148 | +git clone https://github.com/pescheckit/python-gpt-po.git |
| 149 | +cd python-gpt-po |
| 150 | +docker build -t python-gpt-po . |
198 | 151 | ``` |
199 | 152 |
|
200 | | -### Volume Mounting |
201 | | - |
202 | | -Mount any local directory to use in the container: |
203 | | - |
| 153 | +### Run Tests |
204 | 154 | ```bash |
205 | | -# Windows example with OpenAI |
206 | | -docker run -v D:/projects/website/locales:/locales \ |
207 | | - -e OPENAI_API_KEY="your_key" \ |
208 | | - ghcr.io/pescheckit/python-gpt-po:latest \ |
209 | | - --folder /locales --lang fr,de --bulk |
| 155 | +# Local |
| 156 | +python -m pytest |
210 | 157 |
|
211 | | -# Mac/Linux example with Azure OpenAI |
212 | | -docker run -v /Users/username/translations:/input \ |
213 | | - -e AZURE_OPENAI_API_KEY="your_key" \ |
214 | | - -e AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/" \ |
215 | | - -e AZURE_OPENAI_API_VERSION="2024-02-01" \ |
216 | | - ghcr.io/pescheckit/python-gpt-po:latest \ |
217 | | - --provider azure_openai --folder /input --lang fr,de --bulk |
| 158 | +# Docker |
| 159 | +docker run --rm -v $(pwd):/app -w /app --entrypoint python python-gpt-po -m pytest -v |
218 | 160 | ``` |
219 | 161 |
|
220 | | -## Requirements |
221 | | - |
222 | | -- Python 3.9+ (3.9, 3.10, 3.11, or 3.12) |
223 | | -- Core dependencies: |
224 | | - - polib |
225 | | - - openai |
226 | | - - tenacity |
227 | | - - python-dotenv |
228 | | - |
229 | | -## Development |
| 162 | +## 📋 Requirements |
230 | 163 |
|
231 | | -### Running Tests |
232 | | - |
233 | | -```bash |
234 | | -python -m pytest |
235 | | -``` |
236 | | -```bash |
237 | | -docker run --rm -v $(pwd):/app -w /app --entrypoint python python-gpt-po -m pytest -v |
238 | | -``` |
| 164 | +- Python 3.8+ |
| 165 | +- Dependencies: `polib`, `openai`, `anthropic`, `requests`, `tenacity` |
239 | 166 |
|
240 | | -## Documentation |
| 167 | +## 📖 Documentation |
241 | 168 |
|
242 | | -For more detailed information: |
243 | | -- **[Advanced Usage Guide](docs/usage.md)** - Comprehensive guide with all options and internal mechanics |
244 | | -- **[Development Guide](docs/development.md)** - For contributors |
245 | | -- **[GitHub Repository](https://github.com/pescheckit/python-gpt-po)** - Source code and issues |
| 169 | +- **[Advanced Usage Guide](docs/usage.md)** - Comprehensive options and mechanics |
| 170 | +- **[Development Guide](docs/development.md)** - Contributing guidelines |
| 171 | +- **[GitHub Issues](https://github.com/pescheckit/python-gpt-po/issues)** - Bug reports and feature requests |
246 | 172 |
|
247 | | -## License |
| 173 | +## 📄 License |
248 | 174 |
|
249 | | -MIT License - See the [LICENSE](LICENSE) file for details. |
| 175 | +MIT License - See [LICENSE](LICENSE) for details. |
0 commit comments