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
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.0a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f7b7cdc02d309e84128f8dc47a01d933551612e9a8fbe316f41da06e81b2398 |
|
MD5 | 3c090cdc2a95805fc219c88fb2cd8c4a |
|
BLAKE2b-256 | 28da88fc35fae2083845e16463c36640aed381d1feeefb53f42d836fc0c7694f |
Hashes for django_translations-1.0.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8cde017af742079cdee960f92d9f191fce6eb188dc00321262b365569860bb1 |
|
MD5 | 405e5dd5ab1d96da0e2ba77c82e22795 |
|
BLAKE2b-256 | 499755535e21cdff0f391ab9bd776c2c86bf7cf1b40c606acc039eb53fe220bf |