Skip to main content

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(), and exclude() on QuerySets
  • Simple registration system via decorators
  • Integration-ready: autodiscovery of translation.py files
  • Per-language field customization — configure attributes like verbose_name, max_length, default, etc., per field and language via BcTranslationFieldParams

🚀 Installation

pip install bc-model-translator

Add the app to INSTALLED_APPS:

⚙️ Configuration

1. Add the app to INSTALLED_APPS

INSTALLED_APPS = [
    ...
    "bc_modeltranslater",
]

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 django-bc-model-translator 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-bc-model-translator 0.0.1
File Size Uploaded Provenance
django_bc_model_translator-0.0.1.tar.gz 8.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-bc-model-translator 0.0.1
File Interpreter ABI Platform
django_bc_model_translator-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / django_bc_model_translator-0.0.1.tar.gz

Download URL django_bc_model_translator-0.0.1.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b58018f64b8f3a586c0872a5e775adb190449b94293be10915e02a4928b72ac4
BLAKE2b-256 checksum
How to use checksums
0f2425ce61392195e838c4c075f7bd6b5574ab34ccc16f54b1b1e4a2616949d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / django_bc_model_translator-0.0.1-py3-none-any.whl

Download URL django_bc_model_translator-0.0.1-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5791ba5f907a95f000e2d98632c491b5828b949848a1bbf477a48ae198bad4a
BLAKE2b-256 checksum
How to use checksums
a2181f2b10833d45bec2b4ebfbb143f55c51129900b727df5732002dc80a5348
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Security for django-bc-model-translator 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page