Architecture¶
How it works¶
django-traduire sits on top of django-modeltranslation and translation APIs:
Your Django models
|
django-modeltranslation (creates title_fr, title_de, title_en, ...)
|
django-traduire (reads source field, translates, writes target fields)
|
Translation backend (DeepL / Google / OpenAI / custom)
Core flow¶
- Discover fields — queries
modeltranslation.translatorfor registered fields on the model - Read source — reads the source language column (e.g.
title_fr) - Check targets — skips target columns that already have content (unless
overwrite=True) - Batch by language — groups texts by target language for efficient API usage
- Translate — calls the backend's
translate_batch()method - Write back — sets translated values on the instance and saves with
update_fields
Pluggable backends¶
All backends implement BaseBackend with a single required method:
This design means:
- Batch efficiency — one API call per language, not per field
- Easy to extend — implement one method to add a new translation service
- Testable — swap in a fake backend for tests
Settings resolution¶
| Setting | Default | Fallback |
|---|---|---|
SOURCE_LANGUAGE |
None |
LANGUAGE_CODE (stripped of region) |
TARGET_LANGUAGES |
None |
All LANGUAGES except source |
BACKEND |
deepl.DeepLBackend |
— |
AUTO_TRANSLATE |
False |
— |