I have a similar working setup, the main difference is that I use ugettext_lazy . This is because I need to translate these lines into my models or settings when they were available, and not when they were called (which will happen only once: they will be evaluated only at server startup and will not recognize any further changes; Django).
Link: https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#lazy-translation
What I use (in this special case, German is the default language, and I translate into English):
Project /urls.py
from django.conf.urls.i18n import i18n_patterns urlpatterns = i18n_patterns( url(r'^admin/', admin.site.urls), )
Project /settings.py
from django.utils.translation import ugettext_lazy as _ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] LANGUAGE_CODE = 'de-de' USE_I18N = True USE_L10N = True LANGUAGES = [ ('de', _('German')), ('en', _('English')), ] LOCALE_PATHS = [ os.path.join(BASE_DIR, 'locale'), ]
application /models.py
from django.utils.translation import ugettext_lazy as _ class Kindergarten(models.Model): stadt = models.CharField(verbose_name=_(Stadt)) class Meta: verbose_name = _('Kindergarten') verbose_name_plural = _('KindergΓ€rten')
Workflow
$ python manage.py makemessages --locale en ... edit project/locale/en/LC_MESSAGES/django.po ... $ python manage.py compilemessages
Now I can access my Django admin translation (interface + models) with:
Notes
- Pyhton 3.5.2
- Django 1.10.2
tombreit
source share