views:

481

answers:

2

I'm doing a localization of a Django app.

The front-end website works fine and the Django admin site picks up the selected language as well.

But it only applies the language settings in some places and uses the default English versions of field and column names, even though these have been translated. Why? How can I make it use the translated names for column and field names in the admin interface?

Example:

class Order(models.Model):
    OPTIONS = ( (0, _("Bank transfer") ), (1, _("Cash on delivery") ), )

    user = models.ForeignKey(User, name=_("User") )
    payment = models.IntegerField(choices=self.OPTIONS, name=_("Payment"))

For which I get:

  1. Translated standard admin texts such as "Welcome" and "Logout" at the top
  2. Translated SELECT options for the payment type
  3. NOT translated column names and form labels for the fields ("User", "Payment")

I'm using Django 1.0.2. The texts that are not getting translated did appear in the locale files along with those that work.

Sub-question: is it possible to localize the app names?

A: 

Are you perhaps using a custom ModelForm for this model (in admin.py)? You'll need to add a gettext-ed value for the label of the fields you override.

Localizing app names is not possible, as of Django 1.0 - not sure of 1.1.

oggy
+4  A: 

It turned out I was setting a translated version for name instead of verbose_name.

This works:

class Order(models.Model):
    OPTIONS = ( (0, _("Bank transfer") ), (1, _("Cash on delivery") ), )

    user = models.ForeignKey(User, verbose_name=_("User") )
    payment = models.IntegerField(choices=self.OPTIONS, verbose_name=_("Payment"))
TomA