Skip to main content

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 .po files using any LLM supported by LiteLLM (OpenAI, Anthropic, OpenRouter, Ollama, etc.)
  • Plural form support (msgid_plural with msgstr[0], msgstr[1], ...)
  • Auto-discover .po files 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


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.0.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_ai_po-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file django_ai_po-0.1.0.tar.gz.

File metadata

  • Download URL: django_ai_po-0.1.0.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

Hashes for django_ai_po-0.1.0.tar.gz
Algorithm Hash digest
SHA256 735d0a1fdde962722a062a4051fafac5ec5268255574108c54ea2033a45c3fb8
MD5 215eb048031dce2f5442adb5072b6095
BLAKE2b-256 09d7064c18d40c01e02b9fc1140bbea471277c8fe9d4cd72b9ea8a099fca99c0

See more details on using hashes here.

File details

Details for the file django_ai_po-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_ai_po-0.1.0-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

Hashes for django_ai_po-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dcce2ccf1a924e2756d54459c446d4a642321db081bda17990631558d6f061ed
MD5 ecac7aece9397f6d63b02ee7144896a1
BLAKE2b-256 01b29440b3a5c4c1154f592905e2a2faebbe95c8bf72967ae964016d2c87cd65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page