Backends¶
django-traduire ships with three backends. You can also write your own.
DeepL¶
Best quality for European languages. Ideal for Switzerland (fr/de/it/en).
TRADUIRE = {
"BACKEND": "django_traduire.backends.deepl.DeepLBackend",
"BACKEND_OPTIONS": {
"auth_key": "your-deepl-api-key",
},
}
Get your API key at deepl.com/pro-api.
DeepL supports: BG, CS, DA, DE, EL, EN, ES, ET, FI, FR, HU, ID, IT, JA, KO, LT, LV, NB, NL, PL, PT, RO, RU, SK, SL, SV, TR, UK, ZH.
Google Cloud Translation¶
Broadest language coverage, including African languages.
TRADUIRE = {
"BACKEND": "django_traduire.backends.google.GoogleBackend",
"BACKEND_OPTIONS": {
"project_id": "your-gcp-project-id",
},
}
Requires a Google Cloud project with the Translation API enabled and authentication configured (e.g. GOOGLE_APPLICATION_CREDENTIALS).
OpenAI¶
For creative or contextual translations using LLMs.
TRADUIRE = {
"BACKEND": "django_traduire.backends.openai.OpenAIBackend",
"BACKEND_OPTIONS": {
"api_key": "your-openai-api-key",
"model": "gpt-4o-mini", # default
},
}
Works with any OpenAI-compatible API — pass base_url in BACKEND_OPTIONS for Azure, local models, etc.
Custom backend¶
Subclass BaseBackend and implement translate_batch:
from django_traduire.backends.base import BaseBackend
class MyBackend(BaseBackend):
def __init__(self, **kwargs):
# Initialize your client
pass
def translate_batch(self, texts, source, target):
# texts: list of strings
# source: "fr", target: "de"
# Return: list of translated strings
return [my_translate(t, source, target) for t in texts]
Then point to it: