Django internationalization problems

I have template with the following:

{% load i18n %}
  {% trans "Welcome to my site!" %}

I use RequestContext, have called makemessages, edited .po files and compiled messages, but everything is not translated, I just see the same message even when I load the page.

Extract from .po file

msgid "Welcome to my site!"

msgstr "blahblah"

Answers


To get translations to show in templates:

Your settings.py should have the following:

USE_I18N = True
USE_L10N = True # optional, but recommended
LANGUAGE_CODE = 'en-us' # Or whatever language you want as default

You should have 'django.core.context_processors.i18n' in your TEMPLATE_CONTEXT_PROCESSORS

You should add 'django.middleware.locale.LocaleMiddleware' in your MIDDLEWARE_CLASSES (after 'django.contrib.sessions.middleware.SessionMiddleware')

Make sure your templates have {% load i18n %} somewhere near the top.

Once you have translated and compiled the messages, to actually get the translation to show, you need to tell django which language you need. To do that, do one of the following:

  1. Set django_language key in the session which the language code you want.
  2. Set a cookie called django_language to the language you want.

If after all the above, you are not getting any translations to show - then django is not able to find your message files.


Need Your Help

Editable DataGrid in AngularJS

javascript angularjs kendo-ui

Is there any AngularJS module as for DataGrid which provides In-Line Editing? There is one in KendoUI

print and echo commands from php - view when activated remotly for debugging purposes

php json linux debugging

I have an app that use android json php and mysql setup. My question is: