Skip to main content

Django app for seamless AI-assisted translation of .po files.

Project description

dj-translatemessages

LLM-powered Django translations ✨ Formerly published as yesglot.

A Django app that autofills missing translations in .po files using an LLM, while respecting ICU format placeholders and source references.

Project story: The birth of yesglot.com explains the background behind yesglot and the rename to dj-translatemessages.

Why dj-translatemessages?

  • 🧠 LLM-powered: works with 100+ LLM models through LiteLLM’s unified API
  • 🔒 Placeholder-safe: keeps {name}, {{handlebars}}, URLs, and emails intact
  • 📦 Django-native: one management command: python manage.py translatemessages
  • 🧮 Cost-aware: prints per-file and total cost (via LiteLLM)
  • 🧱 Token-safe batching: automatically splits work to avoid context overflows

🚀Quick Start

Installation

pip install dj-translatemessages

Version 2.0.0 renames the Django app to dj_translatemessages. If you're upgrading from yesglot, update INSTALLED_APPS and imports accordingly. Migration steps: docs/migration_guideline.md.

Add dj_translatemessages to your Django settings:

INSTALLED_APPS = [
    # ...
    "dj_translatemessages",
]

Configuration

Set the model from 100+ LLM models and API key in your Django settings:

DJ_TRANSLATEMESSAGES_LLM_MODEL = "openai/gpt-4o-mini"
DJ_TRANSLATEMESSAGES_API_KEY = "sk-..."

Usage

A typical workflow with Django translations:

  1. Extract messages into .po files (creates entries with empty msgstr):
python manage.py makemessages -all
  1. Autofill missing translations with dj-translatemessages:
python manage.py translatemessages

Example output:

▶ Translation run started.
Using translation model: openai/gpt-4o-mini

• Language: French [fr]
  - Scanning: locale/fr/LC_MESSAGES/django.po
    Missing entries: 12. Translating…
    Filled 12 entries in 3.21s • Cost: $0.0123

============================================================
Done in 3.76s • Files: 1 • Missing found: 12 • Filled: 12 • Total cost: $0.0123
  1. Compile translations into .mo files (so Django can use them at runtime):
python manage.py compilemessages

Advanced Usage

Optional parameters,

  • DJ_TRANSLATEMESSAGES_SAFETY_MARGIN: 1000 (default)
  • DJ_TRANSLATEMESSAGES_PER_ITEM_OUTPUT: 100 (default)
  • DJ_TRANSLATEMESSAGES_LLM_MODEL_TEMPERATURE: 0 (default)

System Prompt

It is preconfigured, though you may override it to tailor the behavior of your translation.

  • DJ_TRANSLATEMESSAGES_SYSTEM_PROMPT_FUNCTION: for example, "myproject.myapp.utils.get_system_prompt"
  • DJ_TRANSLATEMESSAGES_SYSTEM_PROMPT: string

Default:

You are a professional translator. Translate into the target language.

  • Keep placeholders like {name} / {{handlebars}} unchanged.
  • Keep URLs and emails unchanged.
  • Return ONLY a JSON array of strings in the same order.

Preamble Template

It’s already configured, but you can override it to adjust how your translation behaves.

  • DJ_TRANSLATEMESSAGES_PREAMBLE_TEMPLATE_FUNCTION: for example, "myproject.myapp.utils.get_preamble"
  • DJ_TRANSLATEMESSAGES_PREAMBLE_TEMPLATE: string

Default:

Translate these items into {language}. Return ONLY a JSON array:

License

Mozilla Public License Version 2.0

dj-translatemessages Logo

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

dj_translatemessages-2.0.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

dj_translatemessages-2.0.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file dj_translatemessages-2.0.0.tar.gz.

File metadata

  • Download URL: dj_translatemessages-2.0.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for dj_translatemessages-2.0.0.tar.gz
Algorithm Hash digest
SHA256 df8f78d20600f60973b0b55a1e74f43991088ade50c1cc4248bb1110c0852b33
MD5 297d04b028aee844e67e9f6a356ed01f
BLAKE2b-256 f0aed114dc5c3e7b23e382933328b4dc4fa2fd538c07be9c73bba8bc178536dd

See more details on using hashes here.

File details

Details for the file dj_translatemessages-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_translatemessages-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce43b9a6d02bcdfe22cade8140e94d1fe89ff7b38392687f33814d8b8e13a796
MD5 ce5d40640bdf7fd77c167c8e00f413d7
BLAKE2b-256 a3caf131ca98053b5cbb084166f0b9b4436e39226f24cba52de13324de324604

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