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.2.tar.gz (18.3 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.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_ai_po-0.1.2.tar.gz
  • Upload date:
  • Size: 18.3 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.2.tar.gz
Algorithm Hash digest
SHA256 728c698a4ba7db770c7e2b695791e58eb1625bacd196a5db1f19d63cebeccccb
MD5 c3ecaaac9e695dc189c8e2c708d62878
BLAKE2b-256 93c2d945f53e7aac7a039acc13e074d0f69fb31cd68963c0132c724c07d1333f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_ai_po-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93076f8e38f73ff6901360ec25b28b9bc75d45d45c624a15aac903ce5fa9cc0e
MD5 22eb02f2418c8a9a3242ac6f18320036
BLAKE2b-256 079ff4ad73f936b3e3fcbb91ce87281db52dfce332a6351d3c94e319ed50b105

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