AI-powered .po file translator for Django using LiteLLM
Project description
django-ai-po
AI-powered .po file translator for Django using LiteLLM.
Features
- Translate Django
.pofiles using any LLM supported by LiteLLM (OpenAI, Anthropic, OpenRouter, Ollama, etc.) - Plural form support (msgid_plural with msgstr[0], msgstr[1], ...)
- Auto-discover
.pofiles in locale directories - Customizable prompt templates per language
- Extensible validation system (built-in Arabic validator, placeholder validator)
- Progress bar via Rich
- Auto-save progress during translation
- Dry-run mode for previewing
- JSON output for CI/CD
Installation
pip install django-ai-po
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...
"django_ai_po",
]
Configuration
Add to your Django settings:
DJANGO_AI_PO = {
"MODEL": "openrouter/google/gemini-2.5-flash-lite",
"API_KEY": "env:OPENROUTER_API_KEY", # or a literal string
"TEMPERATURE": 0.2,
"BATCH_SIZE": 5,
"WORKERS": 2,
"LANGUAGES": {
"ar": {
"validators": ["arabic"],
"prompt_extra": "Use Saudi Arabian healthcare terminology...",
},
},
}
Usage
# Translate a single file
python manage.py translate_po locale/ar/LC_MESSAGES/django.po --lang Arabic
# Auto-discover all .po files for a language
python manage.py translate_po --discover --lang Arabic
# Use a specific model
python manage.py translate_po locale/ar/LC_MESSAGES/django.po --lang Arabic --model anthropic/claude-sonnet-4-20250514
# Dry run (preview without saving)
python manage.py translate_po locale/ar/LC_MESSAGES/django.po --lang Arabic --dry-run
# JSON output for CI/CD
python manage.py translate_po locale/ar/LC_MESSAGES/django.po --lang Arabic --output-format json
Custom Validators
from django_ai_po.translator.validators import BaseValidator
class MyValidator(BaseValidator):
name = "my_validator"
def validate(self, text: str, original: str) -> str:
# Your validation logic
return text
Register it:
from django_ai_po.translator.validators import ValidatorRegistry
ValidatorRegistry.register("my_validator", MyValidator)
Then use in settings:
DJANGO_AI_PO = {
"LANGUAGES": {
"ar": {
"validators": ["arabic", "myapp.validators.MyValidator"],
},
},
}
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django_ai_po-0.1.1.tar.gz
(17.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_ai_po-0.1.1.tar.gz.
File metadata
- Download URL: django_ai_po-0.1.1.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85ea85c5b252c50002946b534581077ec5077d4d229a2b31e89f0a8ca4beb4eb
|
|
| MD5 |
92b0dec8b0955356328f7951d75ed9f8
|
|
| BLAKE2b-256 |
fd685bc55e7b47ac02c8980a1218d3a8ea87afa3ab23bb2b2e1f7150fc9dad9e
|
File details
Details for the file django_ai_po-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_ai_po-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
591b43b5ed38c068a04eddcfc7234c38b0ee5bc8e51d7e4717b94eb8a8965bb0
|
|
| MD5 |
232622820845ab91b9dd521ab73e934a
|
|
| BLAKE2b-256 |
f7710d601bfc19d54da73483bdb96309d1a0b7eafff4c5fc4952efc7d2f5aae1
|