Dealing with Model Content

Strategies

As we discussed in the design decisions one key challenge for our model design is the question of how language interacts with our concept of an object: do we have abstract entities with associated translations, text which only exists in one language or some combination of the two? Do I support only a small number of pre-defined languages or anything which someone on the internet felt like contributing?

This has implications for our database design:
  1. Each object has a language code and no direct links across languages
  2. Each object has separate fields for each language
  3. Each object which defines language-neutral properties (e.g. a City has a country and and a GeoDjango shape) and uses related objects for translation

Any of these could be correct depending on the project. We'll look at two Django apps which help manage the second and third possibilities

django-modeltranslation

This is avoids adding any extra tables or performing extra queries but it will retrieve considerable extra data if you have more than a few languages or very much text. You can compensate partially using Django's defer(), only values or values_list queryset methods to retrieve only the fields you care about at the cost of having to code some language-specific queries.

django-hvad

hvad retrieves only the translations you care about and allows you to avoid duplicating the untranslated portion of your model data. On the downside, every query now involves at least an extra JOIN which may be a performance concern, particularly for MySQL users.

/

#