Backends API¶
django_traduire.backends.base.BaseBackend
¶
Bases: ABC
Abstract base class for translation backends.
Subclasses must implement translate_batch.
Source code in src/django_traduire/backends/base.py
translate_batch(texts, source, target)
abstractmethod
¶
Translate a list of texts from source to target language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
List of strings to translate. |
required | |
source
|
Source language code (e.g. |
required | |
target
|
Target language code (e.g. |
required |
Returns:
| Type | Description |
|---|---|
|
list[str]: Translated texts, same length as input. |
Source code in src/django_traduire/backends/base.py
translate(text, source, target)
¶
Translate a single string. Convenience wrapper around translate_batch.
django_traduire.backends.deepl.DeepLBackend
¶
Bases: BaseBackend
Translation backend using the DeepL API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth_key
|
Your DeepL API authentication key. |
required | |
**kwargs
|
Additional options passed to |
{}
|
Source code in src/django_traduire/backends/deepl.py
django_traduire.backends.google.GoogleBackend
¶
Bases: BaseBackend
Translation backend using Google Cloud Translation API v3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
Your Google Cloud project ID. |
required | |
location
|
API location (default |
'global'
|
|
**kwargs
|
Additional options. |
{}
|
Source code in src/django_traduire/backends/google.py
django_traduire.backends.openai.OpenAIBackend
¶
Bases: BaseBackend
Translation backend using the OpenAI API.
Works with any OpenAI-compatible API (OpenAI, Azure, local models).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Your OpenAI API key. |
None
|
|
model
|
Model to use (default |
'gpt-4o-mini'
|
|
**kwargs
|
Additional options passed to |
{}
|