André
André

Reputation: 25554

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 Django professionals do it?

Give me some clues.

Best Regards,

Upvotes: 0

Views: 430

Answers (2)

Tommaso Barbugli
Tommaso Barbugli

Reputation: 12031

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/

Upvotes: 2

RyanBrady
RyanBrady

Reputation: 6983

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

Upvotes: 2

Related Questions