Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django model i18n of content

In my design there are some models where I need to store certain fields in different languages. Has it be done before? I saw some Django modules that help do model translations but some of them did not work properly.

Any best practices out there? Below is my code.

My model,

class Lookup_I18n(models.Model):
    i18n_code = models.CharField(max_length=5, default=settings.LANGUAGE_CODE)
    value = models.CharField(max_length=300)

class Lookup(models.Model):

    purpose = models.CharField(max_length=10)
    key = models.CharField(max_length=10)
    value_i18n = models.ForeignKey(Lookup_I18n)
    value = models.Field()

    class Meta:
        unique_together = (('purpose', 'key'),)
like image 599
Mo J. Mughrabi Avatar asked Jan 07 '11 15:01

Mo J. Mughrabi


1 Answers

I used recently django_modeltranslation. It will create extra fields in each table for for translation of a field in a certain language. You can provide the translation through Django admin panel. Here are some applications for Django that translate the models. I had to translate just a field in the model and it worked. Choose the application that suits best with your design.

like image 119
Seitaridis Avatar answered Sep 22 '22 15:09

Seitaridis