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.0a4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d00e89b119bdfdbeb0ba7707c01d3f6282f3ad641f3ad1e384f36eeb7062c781 |
|
MD5 | 9a497b10528dbd2eee446fbbe4ea67a0 |
|
BLAKE2b-256 | 41c6a7433193a0e965d9cc46e176f064ef4fb7c9e7c385323280ca7ad1321cd1 |
Hashes for django_translations-1.0.0a4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21e342ecc55f5627021aea13e9632d3bcd7fbd4237e1c24a62daf66a7f818bb8 |
|
MD5 | bb22cf5b1289983909561c23793e9d30 |
|
BLAKE2b-256 | 0c0fe80d73a8be8d0b9012d8463c2eabd2c53c36a6ef6befd9edb9dc861a7afd |