Multilanguage table on Django, how to?
I need to do a App with multilanguage support on Django but I can't figure out the best way of doing it.
Starting with a simple table like this one:
class Genders(models.Model):
n_gender = models.CharField(max_length=60)
I need to have translations for the genders(male, female). What is the approach that I should have doing this task?
There are some apps when I could see how D开发者_如何学Pythonjango professionals do it?
Give me some clues.
Best Regards,
from django.utils.translation import ugettext as _
GENDERS = (('male', _('MALE')), ('female', _('FEMALE')))
class Genders(models.Model):
n_gender = models.CharField(max_length= 60, choices= GENDERS)
and then translate them in the po files (see django docs for how to) http://docs.djangoproject.com/en/1.3/topics/i18n/localization/
Docs on Localization: http://docs.djangoproject.com/en/1.3/topics/i18n/localization/
How To Add Localization to Your Django Project: http://docs.djangoproject.com/en/1.3/howto/i18n/
For an example, try looking at Pinax: https://github.com/pinax/pinax
Template From Pinax using i18n: https://github.com/pinax/pinax/blob/master/pinax/templates/default/account/email.html
精彩评论