[Answered ]-Django change site language

2👍

<form name="setLangEnglish" action="/i18n/setlang/" method="POST">
   {% csrf_token %}
   <input name="next" type="hidden" value="{{request.path}}"/>
   <input type="hidden" name="language" value="en"/>
</form>

What this form actually does is changing your current language to “en” which is english.Since this form input type is hidden,you wouldn’t see form in html. What you have to do is find out how you would like to change language(with clicking text or clicking country flag.).Here is an example for changing langugage with clicking text.

<a onclick="document.setLangEnglish.submit();return false;">ENG</a>

This code submit the form above whenever user clicks “ENG”.In order to be this working, make sure that url(r'^i18n/',include('django.conf.urls.i18n')), is in the urls.py.

👤Brkyrn

Leave a comment