Reusable Django app for dynamic multilingual texts with template tags.
Project description
Django DynamicTexts
Django DynamicTexts is a reusable Django library for dynamically storing and displaying texts (with a unique key, title, and content) with full multilingual (i18n) support. It is ideal for project localization, content management, and SEO-friendly pages.
Features
- Store texts with a unique
key,title, andcontent. - Full translation support (e.g., for English and Latvian) using django-modeltranslation.
- Easy usage in Django templates via custom template tags.
- Content editing via the Django admin interface.
Installation
- Add the app and modeltranslation to
INSTALLED_APPS:INSTALLED_APPS = [ ... 'modeltranslation', 'texts', ]
- Configure languages:
LANGUAGES = [ ('en', 'English'), ('lv', 'Latviešu'), ] MODELTRANSLATION_DEFAULT_LANGUAGE = 'en' MODELTRANSLATION_LANGUAGES = ('en', 'lv') ENABLE_DYNAMIC_TEXT_TRANSLATIONS = True USE_I18N = True MIDDLEWARE = [ ... 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', ... ]
- Run migrations:
python manage.py makemigrations texts python manage.py migrate
- Install dependencies:
pip install django-modeltranslation
Usage
- Add/edit texts in the admin interface (
/admin/), filling in all required translation fields. - Load template tags in your template:
{% load dynamictexts_tags %}
- Display texts in your template:
<h1>{% get_title "about-us" %}</h1> <p>{% get_content "about-us" %}</p>
- The correct translation will be shown automatically based on the active language.
Language Switching
- Use Django's i18n
set_languageview or another language switching mechanism. - Example language switcher form in a template:
<form action="/i18n/setlang/" method="post">{% csrf_token %} <input name="next" type="hidden" value="{{ request.path }}"> <select name="language"> <option value="en">English</option> <option value="lv">Latviešu</option> </select> <input type="submit" value="Change language"> </form> <p>Active language: {{ LANGUAGE_CODE }}</p>
Best Practices
- Always fill in all translation fields in the admin interface.
- Ensure
LocaleMiddlewareis in the correct place in the MIDDLEWARE list. - Use template tags only after
{% load dynamictexts_tags %}. - If you add new languages, update
LANGUAGESand run migrations.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_dynamictexts-0.2.2.tar.gz.
File metadata
- Download URL: django_dynamictexts-0.2.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20cb12d2c280c329c0bb7290f8180e6934677ea50c41774db1f4a0858e4b04b1
|
|
| MD5 |
477fbc5c591ed4bfa1fe2c7a5923627c
|
|
| BLAKE2b-256 |
e51a3a5266cddb312b10370494956bfa6cf1d0377a62fd9c83380dff8f610310
|
File details
Details for the file django_dynamictexts-0.2.2-py3-none-any.whl.
File metadata
- Download URL: django_dynamictexts-0.2.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf86062630a7573b5d41c6fafb6de955b308c906ebdc781f2620056bb6ec0a9
|
|
| MD5 |
c536cdb426afaec3106ec820f3d2a8af
|
|
| BLAKE2b-256 |
f6bc16f97393fca083f298b57db64938c8f5da03bc5c35da7c752960decf67e1
|