django-modeltranslation
django-modeltranslation copied to clipboard
Sugestion: Use jsonfield for translation
In Django 1.9 using Postgresql, we have a extra field, JsonField
https://docs.djangoproject.com/es/1.9/ref/contrib/postgres/fields/#jsonfield
Or can use:
https://github.com/bradjasper/django-jsonfield/
This way, you can use a dynamic translation for each field, just store the language key and the value, like:
{"en": "Title", "pt": "Titulo", "it": "Titolo"}
So, I think you can store every thing on just one field. And don't need to create a lot of field for each language, or when you change a language, you need to migrate the model.
Using Postgre field you can query this fiels like another text field:
class Article(models.Model):
title = models.Charfield()
title_translated = modeltranslation.Charfield(for="title")
query example:
>>> Article.objects.filter(title_translated__en__contains="Title").count()
>>> 1
Works fine!
Ofcourse, this example need to be adapt for modeltranslation API.
+1, came here to suggest this solution and found out somebody beat me to it. Using a JSONField would remove the biggest obstacle when using MANY languages (being that the model gets insanely big).
:+1:
:+1:
Well, even HStoreField would suit this case. However, as we aim to maintain compatibility with MySQL and SQLite databases as well, it's unlikely that we would use this feature. Maybe in some experimental branch.
It would be difficult to create two strategies? One for postgre and another for others? Like the gis integrations do?