Reputation:
I included the following in the settings.py:
LANGUAGES = (
('en', 'English'),
('ru', 'Russian'),
)
LANGUAGE_CODE = 'en-us'
USE_I18N = True
marked the strings to be translated
_('Enterprise') # _ is lazy translate
included this in my URLCOnf:
url(r'^i18n/', include('django.conf.urls.i18n'))
created the locale folder and did this:
python manage.py makemessages -l ru
translated the strings and did this:
python manage.py compilemessages
wrote this form:
<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="/" />
<select name="language">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}">{{ lang.1 }}</option>
{% endfor %}
</select>
<input type="submit" value="Translate" />
</form>
I think I did all the steps to make it work but seems like I doing something wrong or missing something.
When use the form and try to translate and print request.LANGUAGE_CODE
, it is showing me expected value. But the strings remain in the same language as they were
What is wrong here?
Upvotes: 1
Views: 2112
Reputation: 96
Probably you forgot to add the locale middleware into your settings file it should look like this
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
You should take into consideration that the locale middleware should preced the commonmiddleware And comes after the Sessionmiddleware As it takes it argument from the session middleware
Upvotes: 6
Reputation: 20539
You should define your LOCALE_PATHS
in settings.py file like this
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale/'),
)
django doesn't by default look for locale dir in root of project.
Upvotes: 1