Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Django admin use translated field names

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?

like image 537
Tomas Andrle Avatar asked Jul 16 '09 22:07

Tomas Andrle


People also ask

What is Gettext_lazy in Django?

gettext_lazy() In definitions like forms or models you should use gettext_lazy because the code of this definitions is only executed once (mostly on django's startup); gettext_lazy translates the strings in a lazy fashion, which means, eg.

How do I change my Django admin panel name?

To change the admin site header text, login page, and the HTML title tag of our bookstore's instead, add the following code in urls.py . The site_header changes the Django administration text which appears on the login page and the admin site. The site_title changes the text added to the <title> of every admin page.


1 Answers

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"))
like image 177
Tomas Andrle Avatar answered Nov 11 '22 17:11

Tomas Andrle