bc-model-translator
This is a lightweight and extensible Django app for model field translations based on the current active language.
Supports dynamic field registration, localized querying, and transparent field access using Python magic.
✨ Features
- Automatic creation of translated fields (
name_en,name_ru, etc.) - Transparent access to localized values via model attributes
- Language-aware
filter(),get(), andexclude()on QuerySets - Simple registration system via decorators
- Integration-ready: autodiscovery of
translation.pyfiles - Per-language field customization — configure attributes like verbose_name, max_length, default, etc., per field and language via BcTranslationFieldParams
🚀 Installation
pip install bc-django-modeltranslator
Add the app to INSTALLED_APPS:
⚙️ Configuration
1. Add the app to INSTALLED_APPS
INSTALLED_APPS = [
...
"bc_modeltranslator",
]
2. Available settings:
# Temporarily disable translation registration if needed
MODELTRANSLATION_ENABLE_REGISTRATIONS = True
# Filename to look for in each app (default: "translation")
TRANS_FILENAME = "translation"
The TRANS_FILENAME setting defines the file name (without .py) that the app will look for in each Django app to discover translation registration.
🛠️ Usage
Create a translation.py file inside your Django app.
This file is automatically discovered on startup.
# your_app/translation.py
from bc_modeltranslater import register, BcTranslationOptions, BcTranslationField, BcTranslationFieldParams
from .models import TestModel
@register(TestModel)
class SymptomTranslationOptions(BcTranslationOptions):
fields = [
BcTranslationField(field_name="name"),
BcTranslationField(
field_name="desc",
params={
"fr": BcTranslationFieldParams(verbose_name="Description in French"),
"kk": BcTranslationFieldParams(verbose_name="Kazakh description"),
}
)
]
🛠️ Available field parameters
BcTranslationFieldParams(
verbose_name: str | None = None,
default: str | None = None,
blank: bool | None = None,
help_text: str | None = None,
max_length: int | None = None,
null: bool | None = None,
unique: bool | None = None
)
You can define different attributes per language using the params dictionary, where each key is a language code ("en", "ru", "fr", etc.).
🔍 Querying
All query methods automatically use the active language:
from django.utils.translation import activate
activate("ru")
TestModel.objects.filter(name="Имя") # Filters by name_ru
🧠 Field Access
You can access localized values through normal attribute access:
obj = TestModel.objects.first()
print(obj.name) # Returns name_ru or name_en depending on current language
Metadata
Release files for bc-django-modeltranslator 0.0.4
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 | |
|---|---|---|---|---|
| bc_django_modeltranslator-0.0.4.tar.gz | 7.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bc_django_modeltranslator-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.0 kB
Release files / bc_django_modeltranslator-0.0.4.tar.gz
| Download URL | bc_django_modeltranslator-0.0.4.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fca2f08b7a7c6f0ea40d6992ddc1d81ddf43bfe23292337d058f28262eb69fc6
|
|
BLAKE2b-256 checksum How to use checksums |
950e1a1c6d037b78ca9b26aa651fec3911c7cb0581e53db2d2d3159f091150e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Release files / bc_django_modeltranslator-0.0.4-py3-none-any.whl
| Download URL | bc_django_modeltranslator-0.0.4-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd1cff8b4be6c682a451483b42f036c408d13c87ca0cf801bab49dbd6a92c4b5
|
|
BLAKE2b-256 checksum How to use checksums |
aed64c0f504b828b5be706766b567b998a1c64c52f4cc6dafa00b974e22932c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Security for bc-django-modeltranslator 0.0.4
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.