This project was initiated, promoted and accompanied by winePad GmbH (winePad.at). All development based on ideas, experience and support from Maxim Danilov (winePad GmbH).
The background and objectives of this projects are described here
An Application for dynamic translation of existing Django models into any number of languages.
- without need to change existing model classes
- without need to reboot servers
- without changing the use of translated fields
- ready to work after install and indicated in INSTALLED_APPS
- fully integrated in Django modelAdmin, and ModelInline
pip install git+https://github.com/danilovmy/django-tof.git
python manage.py migrate tof
# settings.py
...
INSTALLED_APPS = [
...
'tof',
...
]Don't forget to do if it necessary:
python manage.py collectstatic
Add an existing text field to TOF's "Translatable fields" in the admin. TOF
attaches the descriptor and translation behavior at runtime; the business model
and its normal ModelAdmin do not require a TOF base class. Assigning a string
updates the current Django language. Admin forms offer the available languages.
For individual translation rows, add TranslationTabularInline or
TranslationStackedInline from tof.admin to your normal admin's inlines.
Like a standard using, but it is possible to get a specific translation.
from django.utils.translation import activate
activate('en')
book = Book.objects.first()
book.title # => Title en
book.title.de # => Title deDEFAULT_LANGUAGE in Django settings defaults to "en". Field display uses the
current Django language, then the default language, another nonempty translation,
and finally the original database value. Language codes use their first two
characters. LANGUAGES_SOURCE defaults to tof.models.Language and supplies the
admin language choices; TRANSLATION_ADMINSITE can select a custom admin site.
On PostgreSQL, the native Django compiler loads translations in the same SELECT.
Filtering searches the original value and all translations. An implicit exact
lookup (filter(title="hello")) matches translations without regard to case;
explicit title__exact="hello" preserves case sensitivity. The original column
keeps Django's normal lookup behavior. Ordering uses the displayed translation,
including Meta.ordering, admin ordering, related fields, and expressions, before
pagination. Managers and business model definitions do not need to change.
Other database backends keep Django's native compiler. Translation access can
load extra queries there; translated filtering and ordering require PostgreSQL.
The obsolete FALLBACK_LANGUAGES, DEFAULT_FILTER_LANGUAGE, and
CHANGE_DEFAULT_MANAGER settings are no longer used.
- Python 3.10–3.12; Django 4.2.x or 5.0.x (
>=4.2,<5.1). - PostgreSQL 12 or newer for translated queries (verified locally on 14.21).
psycopg[binary]>=3.1.8,<4is installed because the compiler imports Django's PostgreSQL expressions. CKEditor is optional and is not a runtime dependency.
The existing TOF migration history and Language.id are preserved. Translation
foreign keys continue to store ISO codes through Language.iso. Upgrading does
not require changing business models or regenerating TOF migrations. Filtering
now searches every translation, and default ordering now follows the displayed
translation; review callers relying on the previous behavior.
Install the package and build tools with python -m pip install -e ".[dev]".
The optional [test] extra enables the CKEditor widget regression.
Configure a dedicated PostgreSQL database with TOF_DB_NAME, TOF_DB_USER,
TOF_DB_PASSWORD, TOF_DB_HOST, TOF_DB_PORT, and TOF_TEST_DB_NAME.
Defaults are tof_library, tof_test, an empty password, 127.0.0.1, 5432,
and test_tof_library. The user must be allowed to create the test database.
python -m django test tests --settings=tests.settings --keepdb --noinput
python -m buildTOF_DB_ENGINE=django.db.backends.sqlite3 runs the DB-independent tests and
SQLite smoke checks, skipping PostgreSQL query regressions. The wheel contains
only tof, including its migrations, templates, static assets, and language
fixture. The source distribution additionally includes the standalone tests.
