Thursday, February 2, 2017

set_language language switcher with 3 languages

Hi,

I have a website with 2 languages and am using the standard
{% load i18n %} <form action="{% url 'set_language' %}" method="post">{% csrf_token %} <input name="next" type="hidden" value="{{ redirect_to }}" /> <select name="language"> {% get_current_language as LANGUAGE_CODE %} {% get_available_languages as LANGUAGES %} {% get_language_info_list for LANGUAGES as languages %} {% for language in languages %} <option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}> {{ language.name_local }} ({{ language.code }}) </option> {% endfor %} </select> <input type="submit" value="Go" /> </form>

from https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#the-set-language-redirect-view

But now I'm adding a third language and
<input name="next" type="hidden" value="{{ redirect_to }}" />
is redirecting to the "next" language but not necessarily the one the user selects.

Is there a standard way for solving this? Or do I need to write my own set_language function?

Thanks!



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/517d2433-04c6-4e9b-9259-ced34016bb7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment