[Django]-How to translate a message/variable in Django templates?

3👍

You pointed it out: you can not translate a variable.

You have to translate the text where you define it:

from django.utils.translation import ugettext as _
messages.success(request, _('sign-up-success'))

Then follow the standard translation process : https://docs.djangoproject.com/en/dev/topics/i18n/translation/

0👍

Important thing is to have proper order in middleware in settings.py

  MIDDLEWARE_CLASSES = (
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.locale.LocaleMiddleware',
   'django.middleware.common.CommonMiddleware',
    )

Leave a comment