I'm having difficulty in internationalizing my app, so I present here a minimal example where my implementation fails.
Consider the following steps for producing a website in django with international support:
go to your favorite folder in the terminal and:
django-admin.py startproject mysite
cd mysite/
mkdir locale
python manage.py startapp main
# (1) modify mysite/urls.py
# (2) modify main/views.py
# (3) modify mysite/settings.py
django-admin.py makemessages -l de
# (4) modify locale/de/LC_MESSAGES/django.po
django-admin.py compilemessages -l de
python manage.py runserver
where:
## (1) mysite/urls.py
urlpatterns = patterns('',
url(r'^$', 'main.views.home'),
)
## (2) main/views.py
from django.http import HttpResponse
from django.utils.translation import ugettext as _
def home(request):
return HttpResponse(_('Hello'))
## (3) mysite/settings.py
LANGUAGE_CODE = 'de'
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + \
('django.core.context_processors.i18n',) # ensures all django processors are used.
## (4) locale/de/LC_MESSAGES/django.po
#: main/views.py:6
msgid "Hello"
msgstr "Hallo"
I assume the website has one and only one language, thus, I didn't activated the middleware locale by django documentation:
If you want to let each individual user specify which language he or she prefers, use LocaleMiddleware. LocaleMiddleware enables language selection based on data from the request. It customizes content for each user.
This implementation does not produce the desired translation of "Hello" to "Hallo". What am I doing wrong?