rush
rush

Reputation: 2564

How to translate admin for internal app in django

I've installed django-articles app, unfortunately it doesn't have any translations but english and has very poor internatialization support (only part of messages is in messages.po).

First of all I'm trying to translate admin interface (that' important for me).

However I've a great problem: I can't figure out how Django generates some field name and what should I edit to translate the app.

fieldsets = (
     (None, {'fields': ('title', 'content', 'tags', 'auto_tag', 'status')}),
     ('Relationships', {              
          'fields': ('related_articles','followup_for' ),
          'classes': ('collapse',)
      }),
....

In admin django generate block with subfields "Title", "Content", "Tags", block "Relationships" with subfields "Related articles", "Followup for" with titles in English and so on. ( LANGUAGE_CODE doesn't equal to english)

Where does django this changes and how I can translate it?

ps. I tried to put msgid "Title" (or "title") in messages.po and after compiling messages nothing has changed.

Upvotes: 0

Views: 467

Answers (1)

Grzegorz Biały
Grzegorz Biały

Reputation: 86

Seems like this app doesn't support translation. Strings for translation must be wrapped by gettext function (refer to: https://docs.djangoproject.com/en/dev/topics/i18n/translation/)

E.g. in admin:

 from django.utils.translation import ugettext as _

 ...

 fieldsets = (
 (None, {'fields': ('title', 'content', 'tags', 'auto_tag', 'status')}),
 (_('Relationships'), {              
      'fields': ('related_articles','followup_for' ),
      'classes': ('collapse',)
  }),

Note the _() function I've added.

Translations for model fields have to be done the same way, e.g. in models.py

title = models.CharField(verbose_name=_("Title"))

When you finish you can generate .po file with

./manage.py makemessages -l <language_code>

Please refer to documentation for details.

Upvotes: 2

Related Questions