I've got an issue with translations not working on Django 1.6. I've added this to my settings.py:
LANGUAGE_CODE = 'en-us'
ugettext = lambda s: s
LANGUAGES = (
('en', ugettext('English')),
('de', ugettext('German')),
)
Also added middlewares:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
As well as to my *.py files whenever I'm using a string which shall be l10nd:
from django.utils.translation import ugettext_lazy as _
My templates start with:
{% extends "base.html" %}
{% load i18n %}
And inside the template, I used the trans placeholder. E.g.
<h1>{% trans "Register a tank" %}</h1>
I have provided translations in locale/de/LC_MESSAGES/django.po:
msgid "Register a tank"
msgstr "Einen neuen Tank anmelden"
My browser is set to request German content first: Browser settings
What did I miss?
P.S. The project I'm currently fuzzy around is hosted on GitHub: https://github.com/frlan/blankspot








Add
LOCALE_PATHStosettings.pyand set it as below:Note that
LOCALE_PATHSmust be a tuple (look at the comma at the end of the path).Now based on
LOCALE_PATHS, thelocalefolder should be in the root of your project.And be sure that you run the commands
django-admin.py makemessages -l deanddjango-admin.py compilemessagesfrom the root of your project.Also rearrange your
MIDDLEWARE_CLASSESto beLocaleMiddlewareafterSessionMiddlewareand beforeCommonMiddlewareas mentioned here:Restart your service (
python manage.py runserver) and check again.Just to ensure that your localization is applied to your Django admin page with the default
django.mofile of Django, do the following test:First in main
urls.pyof project replacepatternswithi18n_patterns:Now go to the admin page with a
deprefix, like:http://127.0.0.1:8000/de/admin/And the admin page should be shown in German.OK, are you able to see the admin page of Django in German?
Also check your view with the
deprefix too.According to your project code, some sentences are not in
transblocks. Put them as:Also you must use
ugettext_lazyinstead ofugettextin your code for views and models (Read here and here.)Replace this:
with:
And now everything will work.