I create multilingual flatpages. i want to translate the content according to the language which i select. i refer this code Django i18n setlang view gives Error 404 When i select the language the post method is call i18n/setlang & again comes into same page, but the content is not change. Can anybody help me to solve this problem?
Thanks
settings
gettext = lambda s: s
LANGUAGES = (
('en', gettext('English'),),
('no', gettext('Norwegian'),),
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'multilingual.context_processors.multilingual',
'django.core.context_processors.media',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
template
{% load i18n %}
<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}">{{ language.name }} ({{ language.code }})</option>
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>
**view.py**
def index(request):
return render_to_response('flatpages/index.html', locals(), context_instance=RequestContext(request))
**index.html**
{% block content %}
{% load i18n %}
<h1>{{ flatpage.title }}</h1>
Language Code:{{ LANGUAGE_CODE}}<br>
{% trans "Hello" %}<br>
{% trans "Home" %}<br>
{{ flatpage.content }}
{% endblock content %}
In above code i use the
url (r'^i18n/', include('django.conf.urls.i18n')),
This means when form is submitted it call the method set_language from django's i18n.py file.
I check that method, in that method "check_for_language(lang_code) returns false"
that why the session variable not set.
Can anybody please tell me why this not set?
There will any changes in setting to set path of locale.
I created locale folder in my project folder.