Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Translatable models using one separate model instance per language translation and syncs non language specific fields.

Project description

django-t10e

pypi-badge build-status

django-t10e is an approach that allows you to translate the contents of your models. django-t10e stands for django-translatable.

The concept behind django-t10e is that we have one model instance per language. This means one object that is translated into two different languages will be represented by two rows in the model’s database table. Every translatable model has a language field and a translation_set field.

language obviously defines the language of each translation and translation_set groups the translations of one entity together. All instances with the same translation_set are considered to be different translations of the same entity. An entity might be a news article that is translated into multiple languages..

The translation_set field is a models.ForeignKey('self') field, so it always points to instances of the same model. The first saved instance of one translation will set this foreign key to its own primary key. The instance to which all translations of one entity point to (the first translation) is called the base translation.

An example. Let’s assume the following page instances:

  • Article(id=13, title='I18N is hard', language='en', translation_set=13)
  • Article(id=14, title='Internationalisierung ist schwer', language='de', translation_set=13)
  • Article(id=15, title='La internacionalización es dura', language='es', translation_set=13)

The article with id=13 is considered the base translation. id=14 is the german translation of id=13. id=15 is the spanish translation of id=13. All three make up one translation set for the “I18N is hard” article.

There might also be fields that don’t need translation, like date fields etc. These are synced in the translation set. For example: an article model might have a pub_date field. So all translations in one translation set have the same pub_date value assigned. When one translation is changed you need to call the update_translations() method. That will update all other instances in the translation set accordingly.

Development

Install the dependencies (including the test dependencies) with:

pip install -r requirements.txt

Then you can run all tests with:

tox

Changelog

0.1.0

  • Initital release.

Project details


Release history Release notifications

This version
History Node

0.1.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django-t10e-0.1.0.tar.gz (11.6 kB) Copy SHA256 hash SHA256 Source None Apr 5, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page