Translation of Django Apps

I recently created a Django app that needed translation of the Django administration. It took some googling and messing around to make it work, so this quick and dirty walkthrough will hopefully be helpful for others.

Here’s how I did it:

Add translations for all model fields:

class Stuff(models.Model):
    title = models.CharField(_('title'), max_length=255)
    the_other_model = model.ForeignKey('othermodel', verbose_name=_('the other model'), verbose_name_plural=_('the other models'))
 
    class Meta:
      verbose_name = _('stuff')
      verbose_name_plural = _('stuffs')

Then the language (.po) files must be created:

mkdir locale
python manage.py makemessages -l LANG_CODE

Then edit your language files in locale/_LANGUAGE_/LC_MESSAGES/django.po. When you’ve finished editing the language file must be compiled:

python manage.py compilemessages

If you want to translate app names as well, you can add something like this to your project __init__.py:

from django.utils.translation import ugettext_lazy as _
 
_(u'auth')
_(u'configuration')
_(u'sites')
_(u'appname')
_(u'Auth')
_(u'Configuration')
_(u'Sites')
_(u'Appname')

This feels like a dirty hack but I couldn’t find any other way to do it.

Source: Django documentation – Internationalization and localization, and some Google Groups thread that I can’t find right now, for the app name translation.