Skip to main content

Auto-translate django-modeltranslation fields using DeepL, Google, or OpenAI

Project description

django-traduire

Documentation | PyPI | GitHub

Auto-translate django-modeltranslation fields using DeepL, Google Cloud Translation, or OpenAI.

Fill in content in one language, and django-traduire populates all the other language columns automatically.

Install

pip install django-traduire[deepl]    # DeepL backend
pip install django-traduire[google]   # Google Cloud Translation
pip install django-traduire[openai]   # OpenAI / LLM backend
pip install django-traduire[all]      # All backends

Quick start

# settings.py
INSTALLED_APPS = [
    ...
    "modeltranslation",
    "django_traduire",
]

LANGUAGES = [
    ("fr", "Francais"),
    ("de", "Deutsch"),
    ("en", "English"),
    ("it", "Italiano"),
]

TRADUIRE = {
    "BACKEND": "django_traduire.backends.deepl.DeepLBackend",
    "SOURCE_LANGUAGE": "fr",
    "BACKEND_OPTIONS": {
        "auth_key": "your-deepl-api-key",
    },
}

Translate in Python

from django_traduire import translate_instance

article = Article.objects.get(pk=1)
# article.title_fr = "Bonjour le monde"

translate_instance(article)
# article.title_de = "Hallo Welt"
# article.title_en = "Hello world"
# article.title_it = "Ciao mondo"

Management command

# Translate all registered models
python manage.py traduire

# Translate a specific model
python manage.py traduire myapp.Article

# Overwrite existing translations
python manage.py traduire --overwrite

# Dry run
python manage.py traduire --dry-run

Admin integration

from django.contrib import admin
from modeltranslation.admin import TranslationAdmin
from django_traduire.admin import TraduireMixin

@admin.register(Article)
class ArticleAdmin(TraduireMixin, TranslationAdmin):
    pass

This adds "Translate empty fields" and "Translate all fields (overwrite)" actions to the admin.

Auto-translate on save

TRADUIRE = {
    ...
    "AUTO_TRANSLATE": True,
}

Every time a model is saved, empty translation fields are filled automatically.

Backends

Backend Install Best for
DeepL pip install django-traduire[deepl] European languages, highest quality
Google Cloud pip install django-traduire[google] Broadest language coverage
OpenAI pip install django-traduire[openai] Creative / contextual translations

License

MIT - Paul Guindo / Altius Academy SNC.

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_traduire-0.1.0.tar.gz (15.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_traduire-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_traduire-0.1.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_traduire-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bde6d2dad6c1d283b6ab24c078a681a53fb92276e36b1999d76493cb3343bda4
MD5 79c57982f451c965dc04ae90bc2a53c3
BLAKE2b-256 0032313240f8be710dd57d65477f95011b11240af1fe6eee71590676f624c3c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_traduire-0.1.0.tar.gz:

Publisher: publish.yml on Altius-Academy-SNC/django-traduire

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for django_traduire-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e1cdbdb097487bf37bdb8834952c54b0157c58fff9b893ef2694b9cc1982857
MD5 280afa81853f023ecc335861787396fe
BLAKE2b-256 fed132364683dde25fd43e9b41c1826cf3a80129fb26b85b7518b29694964f35

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_traduire-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Altius-Academy-SNC/django-traduire

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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