django-nublado-translation
A minimal, explicit model-field translation system for Django.
Translations are implemented via a strict two-model contract:
- a source model
- a translation model
No GenericForeignKeys.
No automatic field injection on the source model.
Source model remains unchanged.
Features
- Abstract base models:
TranslationSourceModel:TranslationModel:
- Manager:
TranslationSourceManager: Manager forTranslationSourceManager
- Guarantees:
- One translation per
(source, language). - Source-model unique fields are unique per language in the translation model.
- One translation per
- Base-language fallback support (e.g.,
es-ar→es).
Installation
pip install django-nublado-translation
INSTALLED_APPS = [
...,
"django_nublado_translation",
]
Abstract models
TranslationSourceModel
Base model for translatable objects.
- Translations are stored and cached in a language-code-indexed dictionary
translations_dictfor convenience.
from django.db import models
from django_nublado_translation.models import TranslationSourceModel
from django_nublado_translation.managers import TranslationSourceManager
class Article(TranslationSourceModel):
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, unique=True)
content = models.TextField()
translated_fields = [
"title",
"slug",
"content",
]
objects = TranslationSourceManager()
Notes
translated_fieldsis required for translations, and is the single source of truth for translated fields.TranslationSourceManageris optional, but recommended, to take advantage of its translation-filtering capability.
TranslationModel
Base model for translations of a TranslationSourceModel subclass.
- A foreign key to the source model is generated automatically.
- Default foreign key name:
source. - Default reverse relation name:
translations. - Fields are derived from
translated_fieldsin related source model. - Constraint naming is derived from the translation model name.
Subclasses must define:
source_model- No translated field declarations are allowed on the translation model.
from django_nublado_translation.models import TranslationModel
class ArticleTranslation(TranslationModel):
source_model = Article
# Source object
article = Article.objects.create(
title="Hello everybody",
slug="hello-everybody",
content="Hello, everybody.",
)
# Translation object
ArticleTranslation.objects.create(
source=article,
language="es",
title="Hola a todos",
slug="hola-a-todos",
content="Hola a todos.",
)
Notes
source_namemay be overridden before migrations.- Translated fields are copied from
TranslationSourceModel.translated_fields.
Working with translations
Using a subclass of TranslationSource
Getting translations:
# Assume the default language is "en", available translation languages are
# "es" and "de", and the object has a translation for "es".
# Fetching a translation.
article.get_translation("es")
article.get_translation("es-ar") # Falls back to "es" if no translation found for "es-ar".
article.get_current_translation() # Uses active Django language
- Returns
Noneif no translation exists.
Getting translation information:
# Find out if an object has a translation in a given language.
article.has_translation("es") # True
article.has_translation("de") # False
# Get translation-languages object doesn't have a translation for.
article.get_available_translation_languages() # ["de"]
Cache management for translation_dict.
article.clear_translations_dict_cache()
- Invalidates the internal translation cache.
- Required when translations are modified outside the instance lifecycle.
Using TranslationSourceManager
Prefetching translations
Article.objects.prefetch_translations()
Article.objects.prefetch_translations().filter(slug="source-article-slug")
# Prefetch filtered translations.
translation_qs = ArticleTranslation.objects.filter(language="es", published_status="published")
Article.objects.prefetch_translations(queryset=translation_qs)
App settings
from django_nublado_translation.conf.app_settings import app_settings
app_settings.SOURCE_LANGUAGE
Available settings
| Setting | Default |
|---|---|
SOURCE_LANGUAGE |
django.conf.settings.LANGUAGE_CODE |
Override
DJANGO_NUBLADO_TRANSLATION = {
"SOURCE_LANGUAGE": "en",
}
Testing
pytest
Requires pytest-django.
Metadata
Release files for django-nublado-translation 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_nublado_translation-0.2.2.tar.gz | 14.9 kB | Without provenance | Details for django_nublado_translation-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_nublado_translation-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for django_nublado_translation-0.2.2-py3-none-any.whl |
Total release size: 26.6 kB
Release files / django_nublado_translation-0.2.2.tar.gz
| Download URL | django_nublado_translation-0.2.2.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ca5cf6ac9a97259fafd24a1d11fffd3d86d4395ab731a141bd55f3d4407547b
|
|
BLAKE2b-256 checksum How to use checksums |
c21dc515c7cf03305f2913f4a52cfd3bfb4f7486a920d3f6f863bbcde76dedfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / django_nublado_translation-0.2.2-py3-none-any.whl
| Download URL | django_nublado_translation-0.2.2-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c80cacfd002c5ee89a9540680b2cd70d559d235f23ba24a2dab20cbb3d81f52
|
|
BLAKE2b-256 checksum How to use checksums |
2b570461bac8ac4a5d93bdbed5e22bae8c6f8a59a6fd90b3275c3bd16fe4f0e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for django-nublado-translation 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.