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.0a4.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

django_translations-1.0.0a4-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django-translations-1.0.0a4.tar.gz
Algorithm Hash digest
SHA256 d00e89b119bdfdbeb0ba7707c01d3f6282f3ad641f3ad1e384f36eeb7062c781
MD5 9a497b10528dbd2eee446fbbe4ea67a0
BLAKE2b-256 41c6a7433193a0e965d9cc46e176f064ef4fb7c9e7c385323280ca7ad1321cd1

See more details on using hashes here.

Provenance

File details

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

File metadata

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

File hashes

Hashes for django_translations-1.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 21e342ecc55f5627021aea13e9632d3bcd7fbd4237e1c24a62daf66a7f818bb8
MD5 bb22cf5b1289983909561c23793e9d30
BLAKE2b-256 0c0fe80d73a8be8d0b9012d8463c2eabd2c53c36a6ef6befd9edb9dc861a7afd

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