Skip to main content

A Django app which provides support for model translation.

Project description

https://travis-ci.com/perplexionist/django-translations.svg?branch=master

Translations app provides an easy, efficient and modular way of translating Django models.

Requirements

  • Python (>=3.5)

  • Django (1.11, >=2.0)

Installation

  1. Install Translations using PIP (use --pre, still in development):

    $ pip install --pre django-translations
  2. Add 'translations' to INSTALLED_APPS in the settings of your Django project:

    INSTALLED_APPS += [
        'translations',
    ]
  3. Run migrate:

    $ python manage.py migrate
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-translations-1.0.0b3.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

django_translations-1.0.0b3-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file django-translations-1.0.0b3.tar.gz.

File metadata

  • Download URL: django-translations-1.0.0b3.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for django-translations-1.0.0b3.tar.gz
Algorithm Hash digest
SHA256 d1043a2d5f0f08dd6b4a56a5a324eb55f2502fd3232d4872fa1ca7250d4b3b25
MD5 a6e988070928b086ec9e87270ac3147c
BLAKE2b-256 0a60c6fb96fe9d8c2744ba213c88ed0ec78eeb6e9a9e5eb388239ba4448e98e0

See more details on using hashes here.

Provenance

File details

Details for the file django_translations-1.0.0b3-py3-none-any.whl.

File metadata

  • Download URL: django_translations-1.0.0b3-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for django_translations-1.0.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 15e07dab4eccdd54d52829469014649e9fdadc9961cb599300f2c988090be617
MD5 f4adacb44adb4d75664acd4d7cad2b72
BLAKE2b-256 0e6c7633dfc604170c808c514aeb9f714f0bb35c21a7626db1b899ba7b63a6f2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page