A Django app which provides support for model translation.
Project description
Translations app provides an easy, efficient and modular way of translating Django models.
Requirements
Python (>=3.5)
Django (1.11, >=2.0)
Installation
Install Translations using PIP (use --pre, still in development):
$ pip install --pre django-translations
Add 'translations' to INSTALLED_APPS in the settings of your Django project:
INSTALLED_APPS += [ 'translations', ]
Run migrate:
$ python manage.py migrate
Make sure django internationalization settings are set correctly:
USE_I18N = True # use internationalization USE_L10N = True # use localization MIDDLEWARE += [ # locale middleware 'django.middleware.locale.LocaleMiddleware', ] LANGUAGE_CODE = 'en-us' # fallback language LANGUAGES = ( # supported languages ('en', 'English'), ('de', 'German'), )
Basic Usage
Model
Inherit Translatable in any model you want translated:
from translations.models import Translatable
class Continent(Translatable):
...
class Country(Translatable):
...
class City(Translatable):
...
No Migrations needed afterwards!
Query
Use the queryset extensions:
>>> # 1. query the database
>>> continents = Continent.objects.prefetch_related(
... 'countries',
... 'countries__cities'
... )
>>> # 2. apply the translations (in place)
>>> continents.apply_translations(
... 'countries',
... 'countries__cities',
... lang='de'
... )
>>> # 3. use it like before
>>> continents[0].name
Europa
>>> continents[0].countries.all()[0].name
Deutschland
This does Only One Query for the translations of the queryset and the specified relations!
Admin
Use the admin extensions:
from translations.admin import TranslatableAdmin, TranslationInline
class ContinentAdmin(TranslatableAdmin):
inlines = [TranslationInline,]
This provides specialized translation inlines for the model.
Documentation
For more interesting capabilities browse through the documentation.
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
Hashes for django-translations-1.0.0b2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 567dcbbbb3741765f6bd35d1dac2a7a3cc9cd26318f9ddb82aec647d188890d7 |
|
MD5 | 519cfa9d3bb04b06bd739d8f9dd415c9 |
|
BLAKE2b-256 | d1f5afc05b7e816e25c3b83d318197920a085a947602042ab296455972ddcbab |
Hashes for django_translations-1.0.0b2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15da7f3de7ade4e96fed3699c73ca51f176dbcf6a29d33ce3c2c245eddf09cb7 |
|
MD5 | c95a69295a72d2de29b3273556d89a36 |
|
BLAKE2b-256 | c6d46b9d9048ec5a6405d0d125e51bfe7cffdded11dd97a2ebd7b285e8cad3b4 |