How to translate Lookup values in Django?

78 views
Skip to first unread message

Houmie

unread,
Oct 2, 2012, 6:23:34 PM10/2/12
to django...@googlegroups.com

Django has an excellent support for internationalization, any English expression within Models, Forms, View or template can easily be marked for translation. However I came across an interesting situation I don't know how to deal with.

I have a Gender lookup (Male, Female). Now even if I translated the site into German, the Gender dropdown is still pointing to the values saved in database, which happens to be in English. So How am I supposed to mark the values in the database to be translated in PO files?

class Gender(models.Model):
    gender      
= models.CharField(_(u'Sex'), max_length=10)    
   
def __unicode__(self):
       
return self.gender
   
class Meta:
        verbose_name
= _(u'Sex')
        verbose_name_plural
= _(u'Sexes')


Many Thanks,

Juan Pablo Martínez

unread,
Oct 2, 2012, 8:57:41 PM10/2/12
to django...@googlegroups.com
GENDER_CHOICES = (
('male', _(u'Male')),
('female', _(u'Female')),
)
gender      
= models.CharField(_(u'Sex'), max_length=10, choices=GENDER_CHOICES)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/mLjpKAPU1NAJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
juanpex

Houman

unread,
Oct 2, 2012, 9:08:30 PM10/2/12
to django...@googlegroups.com
Thanks Juan. 

Well that is certainly possible. But then we have also some other lookups like the country, which is a lookup of 139 values. It would be difficult to keep that in the model itself. ;-)
But you are right about smaller lookups.

Regards,
Houman

Juan Pablo Martínez

unread,
Oct 3, 2012, 10:01:19 AM10/3/12
to django...@googlegroups.com
Then you could come here and test if it's

https://github.com/juanpex/django-model-i18n/

Regards,
--
juanpex

Jair Trejo

unread,
Oct 3, 2012, 11:34:55 AM10/3/12
to django...@googlegroups.com
I use django-datatrans for catalog translation, i'ts not perfect but good enough for me.

houmie

unread,
Oct 3, 2012, 12:32:07 PM10/3/12
to django...@googlegroups.com
Thanks guys. I came across myself across django-modeltranslation and I must it works very well.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/3U8FtzKa9IIJ.
Reply all
Reply to author
Forward
0 new messages