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:
>>> continents = Continent.objects.prefetch_related(
... 'countries',
... 'countries__cities',
... ).apply_translations(
... 'countries',
... 'countries__cities',
... lang='de'
... )
>>> continents[0].name
Europa
>>> continents[0].countries.all()[0].name
Deutschland
This does Only One Query for the queryset and relations translations!
Admin
Use the admin extensions:
from django.contrib import admin
from translations.admin import TranslatableAdmin, TranslationInline
from .models import Continent
class ContinentAdmin(TranslatableAdmin):
inlines = [TranslationInline,]
admin.site.register(Continent, ContinentAdmin)
This provides admin inlines for the translations of 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.0a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958f2dd42eb85dd7e554ee42c46fbba891cc403b909d874a24759be38507e559 |
|
MD5 | 840d472d814ee98e181b8fc000a817d0 |
|
BLAKE2b-256 | 494cdd189e1cf19bd4d3fe757dae3714615bf9b0c83189787be473c6e66cf36d |
Hashes for django_translations-1.0.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30bf4e487fb74d773a6454b53a55829576367eccd8d23e856ea73db37ca9fb56 |
|
MD5 | 17ba4abd37fbf240e6462494b46ebc1d |
|
BLAKE2b-256 | 52f5d4a7950b71109a97437b46d59342b125dd4b4921e7a0f5e7d48990691390 |