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.
[...] names is kind of a mystery for me as well. I saw this guy using the __init__.py and adding application names there. It works for me – my application [...]
Django translations: multilingual, i18n, app names | Mario Peshev - Freelance developer and consultant
9 Aug 10 at 01:11
[...] Затем нагуглил довольно интересный «способ» — http://grx.no/kb/2010/03/04/translation-of-django-apps/ но и он не сработал… я наверное не совсем понимаю [...]
Имена приложений Django, перевод с помощью i18in (наверное очередная тема…)
30 Sep 10 at 21:50