Note that there are some explanatory texts on larger screens.

plurals
  1. POLanguage Translation in Django using i18n
    primarykey
    data
    text
    <p>I create multilingual flatpages. i want to translate the content according to the language which i select. i refer this code <a href="https://stackoverflow.com/questions/10898614/django-i18n-setlang-view-gives-error-404?answertab=active">Django i18n setlang view gives Error 404</a> When i select the language the post method is call i18n/setlang &amp; again comes into same page, but the content is not change. Can anybody help me to solve this problem?</p> <p>Thanks</p> <p><strong>settings</strong></p> <pre><code>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', ) </code></pre> <p><strong>template</strong></p> <pre><code>{% load i18n %} &lt;form action="/i18n/setlang/" method="post"&gt; {% csrf_token %} &lt;input name="next" type="hidden" value="{{ redirect_to }}" /&gt; &lt;select name="language"&gt; {% get_language_info_list for LANGUAGES as languages %} {% for language in languages %} &lt;option value="{{ language.code }}"&gt;{{ language.name }} ({{ language.code }})&lt;/option&gt; {% endfor %} &lt;/select&gt; &lt;input type="submit" value="Go" /&gt; &lt;/form&gt; **view.py** def index(request): return render_to_response('flatpages/index.html', locals(), context_instance=RequestContext(request)) **index.html** {% block content %} {% load i18n %} &lt;h1&gt;{{ flatpage.title }}&lt;/h1&gt; Language Code:{{ LANGUAGE_CODE}}&lt;br&gt; {% trans "Hello" %}&lt;br&gt; {% trans "Home" %}&lt;br&gt; {{ flatpage.content }} {% endblock content %} </code></pre> <p>In above code i use the<br> url (r'^i18n/', include('django.conf.urls.i18n')),<br> This means when form is submitted it call the method set_language from django's i18n.py file. </p> <p>I check that method, in that method "check_for_language(lang_code) returns false"<br> that why the session variable not set.</p> <p>Can anybody please tell me why this not set?<br> There will any changes in setting to set path of locale.<br> I created locale folder in my project folder.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload