doniyor
doniyor

Reputation: 37846

django - set_language() trans url

may be this is already done somewhere, but let me ask this again.

I have this select options with language to change the language of the page

<form action="{% url 'set_language' %}" method="post">
   {% csrf_token %}
   <input name="next" type="hidden" value="{% trans request.path %}" />
   <select name="language" class="langoption">
     {% for lang in LANGUAGES %}
        <option value="{{lang.0}}" {% if lang.0 == LANGUAGE_CODE %} selected {% endif %}>
            {{lang.1}}
        </option>
     {% endfor %}
   </select>
</form>

and lets say, user is in page /horoscope/ and my urls.py has this face:

url(_(r'^horoscope/$'), TemplateView.as_view(template_name="horoskope.html"), name="horoscope"),

and there is a translation for "^horoscope/$" in .po file: "^horoskop/$" (german translation)

How, If I change the language to german, django succesfully changing it, but i am getting 404 page because it is redirecting to /horoscope/ which doesnot exist anymore in urls.py.. which changed to /horoskop/. how can i solve this issue?

I tried to give

<input name="next" type="hidden" value="{% trans request.path %}" />

but it is still in current language.

appreciate any hand for help

Upvotes: 0

Views: 328

Answers (1)

Norman8054
Norman8054

Reputation: 824

Do you have access to the 'set_language' view? There you can control the redirection and there you have to translate the given value of the 'next' form field from the previous language to the current one.

Upvotes: 1

Related Questions