|
1 |
| -# Python GPT-4 PO File Translator |
| 1 | +# GPT-PO Translator |
2 | 2 |
|
3 | 3 | [](https://github.com/pescheckit/python-gpt-po/actions/workflows/ci-cd.yml)
|
4 | 4 | 
|
5 | 5 | 
|
6 | 6 |
|
7 | 7 | A robust tool for translating gettext (.po) files using AI models from multiple providers (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.
|
8 | 8 |
|
9 |
| -## Features |
| 9 | +## What is GPT-PO Translator? |
10 | 10 |
|
11 |
| -- **Multi-Provider Support:** Integrates with OpenAI, Anthropic / Claude, and DeepSeek. |
12 |
| -- **Bulk & Individual Modes:** Translate entire files in batches or process entries one by one. |
13 |
| -- **Fuzzy Entry Management:** Automatically removes fuzzy entries to ensure clean translations. |
14 |
| -- **Folder-Based Language Inference:** Detects the target language from directory structure. |
15 |
| -- **Customizable Batch Size:** Configure the number of entries per translation request. |
16 |
| -- **Retry & Validation:** Automatic retries and validation to ensure concise, correct translations. |
17 |
| -- **Detailed Logging:** Transparent logging for progress monitoring and debugging. |
18 |
| -- **Flexible API Key Configuration:** Supply API keys via environment variables or command-line arguments. |
19 |
| -- **Detailed Language Option:** Use full language names (e.g., "German") for clearer prompts alongside language codes (e.g., de). |
| 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. |
20 | 12 |
|
21 |
| -## Requirements |
| 13 | +### Key Features |
22 | 14 |
|
23 |
| -- Python 3.8+ (Python 3.8, 3.9, 3.10, 3.11, and 3.12 are officially supported) |
24 |
| -- [polib](https://pypi.org/project/polib/) |
25 |
| -- [openai](https://pypi.org/project/openai/) |
26 |
| -- [tenacity](https://pypi.org/project/tenacity/) |
27 |
| -- [python-dotenv](https://pypi.org/project/python-dotenv/) |
| 15 | +- **Multiple AI providers** - 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 | +- **Production-ready** - Includes retry logic, validation, and detailed logging |
| 19 | +- **Easy deployment** - Available as a Python package or Docker container |
| 20 | +- **Cross-version support** - Works with Python 3.8-3.12 |
28 | 21 |
|
29 |
| -## Installation |
| 22 | +## Getting Started |
30 | 23 |
|
31 |
| -### Via PyPI |
| 24 | +### Quick Install |
32 | 25 |
|
33 | 26 | ```bash
|
34 | 27 | pip install gpt-po-translator
|
35 | 28 | ```
|
36 | 29 |
|
37 |
| -### Manual Installation |
| 30 | +### Basic Usage |
| 31 | + |
| 32 | +```bash |
| 33 | +# Set up your API key |
| 34 | +export OPENAI_API_KEY='your_api_key_here' |
| 35 | + |
| 36 | +# Translate files to German and French |
| 37 | +gpt-po-translator --folder ./locales --lang de,fr --bulk |
| 38 | +``` |
38 | 39 |
|
39 |
| -Clone the repository and install the package: |
| 40 | +## Installation Options |
| 41 | + |
| 42 | +### PyPI (Recommended) |
| 43 | + |
| 44 | +```bash |
| 45 | +pip install gpt-po-translator |
| 46 | +``` |
| 47 | + |
| 48 | +### Manual Installation |
40 | 49 |
|
41 | 50 | ```bash
|
42 | 51 | git clone https://github.com/pescheckit/python-gpt-po.git
|
43 | 52 | cd python-gpt-po
|
44 | 53 | python3 -m venv .venv
|
45 | 54 | source .venv/bin/activate
|
46 | 55 | pip install -r requirements.txt
|
47 |
| -python -m python_gpt_po.main --provider="deepseek" --list-models |
48 | 56 | ```
|
49 | 57 |
|
50 |
| -## API Key Configuration |
| 58 | +### Docker |
51 | 59 |
|
52 |
| -You can provide your API key in two ways: |
| 60 | +```bash |
| 61 | +# Pull the latest image |
| 62 | +docker pull ghcr.io/pescheckit/python-gpt-po:latest |
53 | 63 |
|
54 |
| -### Environment Variable |
| 64 | +# Run with your local directory mounted |
| 65 | +docker run -v $(pwd):/data \ |
| 66 | + -e OPENAI_API_KEY="your_key" \ |
| 67 | + ghcr.io/pescheckit/python-gpt-po:latest \ |
| 68 | + --folder /data --lang fr,de --bulk |
| 69 | +``` |
| 70 | + |
| 71 | +## Setting Up API Keys |
55 | 72 |
|
56 |
| -Set your OpenAI API key: |
| 73 | +### Option 1: Environment Variables |
57 | 74 |
|
58 | 75 | ```bash
|
59 | 76 | export OPENAI_API_KEY='your_api_key_here'
|
| 77 | +# Or for other providers: |
| 78 | +export ANTHROPIC_API_KEY='your_api_key_here' |
| 79 | +export DEEPSEEK_API_KEY='your_api_key_here' |
60 | 80 | ```
|
61 | 81 |
|
62 |
| -### Command-Line Argument |
63 |
| - |
64 |
| -Pass your API key directly when invoking the tool: |
| 82 | +### Option 2: Command Line |
65 | 83 |
|
66 | 84 | ```bash
|
67 |
| -gpt-po-translator --folder ./locales --lang de,fr --api_key 'your_api_key_here' --bulk --bulksize 100 --folder-language |
| 85 | +gpt-po-translator --api_key 'your_api_key_here' [other options] |
68 | 86 | ```
|
69 | 87 |
|
70 |
| -## Usage |
| 88 | +## Usage Examples |
71 | 89 |
|
72 |
| -Run the tool from the command line to translate your .po files: |
| 90 | +### Basic Translation |
73 | 91 |
|
74 | 92 | ```bash
|
75 |
| -gpt-po-translator --folder <path_to_po_files> --lang <language_codes> [options] |
| 93 | +# Translate to German |
| 94 | +gpt-po-translator --folder ./locales --lang de |
76 | 95 | ```
|
77 | 96 |
|
78 |
| -### Example |
79 |
| - |
80 |
| -Translate .po files in the `./locales` folder to German and French: |
| 97 | +### Bulk Translation with Language Detection |
81 | 98 |
|
82 | 99 | ```bash
|
83 |
| -gpt-po-translator --folder ./locales --lang de,fr --api_key 'your_api_key_here' --bulk --bulksize 40 --folder-language --detail-lang "German,French" |
| 100 | +# Translate based on folder structure with custom batch size |
| 101 | +gpt-po-translator --folder ./locales --lang de,fr --bulk --bulksize 40 --folder-language |
84 | 102 | ```
|
85 | 103 |
|
86 |
| -## Documentation |
87 |
| - |
88 |
| -For a detailed explanation of all available parameters and a deep dive into the internal workings of the tool, please see our [Advanced Usage Guide](docs/usage.md). |
89 |
| - |
90 |
| -## Command-Line Options |
91 |
| - |
92 |
| -- `--folder`: Path to the directory containing .po files. |
93 |
| -- `--lang`: Comma-separated target language codes (e.g., de,fr). |
94 |
| -- `--detail-lang`: Comma-separated full language names corresponding to the codes (e.g., "German,French"). |
95 |
| -- `--fuzzy`: Remove fuzzy entries before processing. |
96 |
| -- `--bulk`: Enable bulk translation mode. |
97 |
| -- `--bulksize`: Set the number of entries per bulk translation (default is 50). |
98 |
| -- `--model`: Specify the translation model (defaults are provider-specific). |
99 |
| -- `--provider`: Specify the AI provider (openai, anthropic, or deepseek). |
100 |
| -- `--list-models`: List available models for the selected provider. This is the only command that can be used without `--folder` and `--lang`. |
101 |
| -- `--api_key`: API key for translation; can also be provided via environment variable. |
102 |
| -- `--folder-language`: Infer the target language from the folder structure. |
103 |
| - |
104 |
| -## Logging & Error Handling |
105 |
| - |
106 |
| -- **Logging:** Detailed logs track the translation process and help with debugging. |
107 |
| -- **Error Handling:** The tool automatically retries failed translations (up to three times) and validates output to prevent overly verbose responses. |
| 104 | +### Using Different AI Providers |
108 | 105 |
|
109 |
| -## Testing |
| 106 | +```bash |
| 107 | +# Use Claude models from Anthropic |
| 108 | +gpt-po-translator --provider anthropic --folder ./locales --lang de |
110 | 109 |
|
111 |
| -To run all tests: |
| 110 | +# Use DeepSeek models |
| 111 | +gpt-po-translator --provider deepseek --folder ./locales --lang de |
112 | 112 |
|
113 |
| -```bash |
114 |
| -python -m pytest |
| 113 | +# List available models |
| 114 | +gpt-po-translator --provider openai --list-models |
115 | 115 | ```
|
116 | 116 |
|
117 |
| -## Using Docker |
| 117 | +## Command Reference |
118 | 118 |
|
119 |
| -You can use this tool without installing Python on your local machine by running it in a Docker container. |
| 119 | +| Option | Description | |
| 120 | +|--------|-------------| |
| 121 | +| `--folder` | Path to your .po files | |
| 122 | +| `--lang` | Target language codes (comma-separated, e.g., `de,fr`) | |
| 123 | +| `--detail-lang` | Full language names (e.g., `"German,French"`) | |
| 124 | +| `--fuzzy` | Remove fuzzy entries before translating | |
| 125 | +| `--bulk` | Enable batch translation (recommended for large files) | |
| 126 | +| `--bulksize` | Entries per batch (default: 50) | |
| 127 | +| `--model` | Specific AI model to use | |
| 128 | +| `--provider` | AI provider: `openai`, `anthropic`, or `deepseek` | |
| 129 | +| `--list-models` | Show available models for selected provider | |
| 130 | +| `--api_key` | Your API key | |
| 131 | +| `--folder-language` | Auto-detect languages from folder structure | |
120 | 132 |
|
121 |
| -### Using Pre-built Container |
| 133 | +## Advanced Docker Usage |
122 | 134 |
|
123 |
| -Pull the latest container from GitHub Container Registry (defaults to Python 3.11): |
| 135 | +### Specific Python Versions |
124 | 136 |
|
125 | 137 | ```bash
|
126 |
| -docker pull ghcr.io/pescheckit/python-gpt-po:latest # Uses Python 3.11 by default |
127 |
| -``` |
| 138 | +# Python 3.11 (default) |
| 139 | +docker pull ghcr.io/pescheckit/python-gpt-po:latest |
128 | 140 |
|
129 |
| -You can also use a specific version tag for consistency, or specify a Python version: |
| 141 | +# Python 3.12 |
| 142 | +docker pull ghcr.io/pescheckit/python-gpt-po:latest-py3.12 |
130 | 143 |
|
131 |
| -```bash |
132 |
| -docker pull ghcr.io/pescheckit/python-gpt-po:0.3.0 # Latest version |
133 |
| -docker pull ghcr.io/pescheckit/python-gpt-po:0.3.0-py3.11 # Python 3.11 specific |
134 |
| -docker pull ghcr.io/pescheckit/python-gpt-po:latest-py3.12 # Latest with Python 3.12 |
| 144 | +# Specific version |
| 145 | +docker pull ghcr.io/pescheckit/python-gpt-po:0.3.0 |
135 | 146 | ```
|
136 | 147 |
|
137 |
| -Run the container with any local directory mounted to any path inside the container: |
| 148 | +### Volume Mounting |
138 | 149 |
|
139 |
| -```bash |
140 |
| -# Mount current directory to /data in container |
141 |
| -docker run -v $(pwd):/data \ |
142 |
| - -e OPENAI_API_KEY="your_openai_key" \ |
143 |
| - ghcr.io/pescheckit/python-gpt-po:latest \ |
144 |
| - --folder /data --lang fr,de --bulk |
| 150 | +Mount any local directory to use in the container: |
145 | 151 |
|
146 |
| -# Mount a specific absolute path to /translations in container |
147 |
| -docker run -v /home/user/my-translations:/translations \ |
148 |
| - -e OPENAI_API_KEY="your_openai_key" \ |
149 |
| - ghcr.io/pescheckit/python-gpt-po:latest \ |
150 |
| - --folder /translations --lang fr,de --bulk |
151 |
| - |
152 |
| -# Mount from a different drive or location on Windows |
| 152 | +```bash |
| 153 | +# Windows example |
153 | 154 | docker run -v D:/projects/website/locales:/locales \
|
154 |
| - -e OPENAI_API_KEY="your_openai_key" \ |
| 155 | + -e OPENAI_API_KEY="your_key" \ |
155 | 156 | ghcr.io/pescheckit/python-gpt-po:latest \
|
156 | 157 | --folder /locales --lang fr,de --bulk
|
157 |
| - |
158 |
| -# On Mac/Linux, mount from any location |
159 |
| -docker run -v /Users/username/Documents/translations:/input \ |
160 |
| - -e OPENAI_API_KEY="your_openai_key" \ |
161 |
| - ghcr.io/pescheckit/python-gpt-po:latest \ |
162 |
| - --folder /input --lang fr,de --bulk |
163 |
| - |
164 |
| -# Multiple volumes can be mounted if needed |
165 |
| -docker run \ |
166 |
| - -v /path/to/source:/input \ |
167 |
| - -v /path/to/output:/output \ |
168 |
| - -e OPENAI_API_KEY="your_openai_key" \ |
| 158 | + |
| 159 | +# Mac/Linux example |
| 160 | +docker run -v /Users/username/translations:/input \ |
| 161 | + -e OPENAI_API_KEY="your_key" \ |
169 | 162 | ghcr.io/pescheckit/python-gpt-po:latest \
|
170 | 163 | --folder /input --lang fr,de --bulk
|
171 | 164 | ```
|
172 | 165 |
|
173 |
| -Running without arguments will display usage help: |
174 |
| - |
175 |
| -```bash |
176 |
| -docker run ghcr.io/pescheckit/python-gpt-po:latest |
177 |
| -``` |
| 166 | +## Requirements |
178 | 167 |
|
179 |
| -Quick reference - copy & paste commands: |
| 168 | +- Python 3.9+ (3.9, 3.10, 3.11, or 3.12) |
| 169 | +- Core dependencies: |
| 170 | + - polib |
| 171 | + - openai |
| 172 | + - tenacity |
| 173 | + - python-dotenv |
180 | 174 |
|
181 |
| -```bash |
182 |
| -# Help text |
183 |
| -docker run ghcr.io/pescheckit/python-gpt-po:latest |
| 175 | +## Development |
184 | 176 |
|
185 |
| -# Translate current directory files to French |
186 |
| -docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest --folder /data --lang fr |
| 177 | +### Running Tests |
187 | 178 |
|
188 |
| -# Use a specific Python version (3.12) |
189 |
| -docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest-py3.12 --folder /data --lang fr |
190 |
| - |
191 |
| -# List available models (no need for --folder or --lang) |
192 |
| -docker run -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest --provider openai --list-models |
| 179 | +```bash |
| 180 | +python -m pytest |
193 | 181 | ```
|
194 | 182 |
|
195 |
| -### Volume Mount Explanation |
196 |
| - |
197 |
| -The `-v` flag uses the format: `-v /host/path:/container/path` |
198 |
| - |
199 |
| -- `/host/path` can be any directory on your system |
200 |
| -- `/container/path` is where the directory appears inside the container |
201 |
| -- Use the `/container/path` with the `--folder` parameter |
| 183 | +## Documentation |
202 | 184 |
|
203 |
| -For example, if you mount with `-v ~/translations:/data`, then use `--folder /data` in your command. |
| 185 | +For advanced usage and detailed documentation, please see: |
| 186 | +- [Advanced Usage Guide](docs/usage.md) |
| 187 | +- [GitHub Repository](https://github.com/pescheckit/python-gpt-po) |
204 | 188 |
|
205 | 189 | ## License
|
206 | 190 |
|
207 |
| -This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
208 |
| - |
209 |
| -## About |
210 |
| - |
211 |
| -Powered by state-of-the-art AI models (including OpenAI’s GPT-4 and GPT-3.5), this tool is designed to streamline the localization process for .po files. Whether you need to process large batches or handle specific entries, the Python GPT-4 PO File Translator adapts to your translation needs. |
212 |
| - |
213 |
| -For more details, contributions, or bug reports, please visit our [GitHub repository](https://github.com/pescheckit/python-gpt-po). |
| 191 | +MIT License - See the [LICENSE](LICENSE) file for details. |
0 commit comments