I am using Django and developing an i18n site serving many languages. I want to make a modal that stays in base.html, so that users can switch the language wherever they are.
I managed to do something like this.
<div class="modal-body">
{% get_available_languages as languages %}
{% for lang_code, lang_name in languages %}
{% language lang_code %}
<a href="{% url 'home' %}" class="btn lang-btn {% ifequal request.LANGUAGE_CODE lang_code %}selected{% endifequal %}">{{lang_code|lang_name}}</a>
{% endlanguage %}
{% endfor %}
</div>
Which turns out urls like:/ja/
, /en/
, /fr/
, etc..
but this kind of approach links to the main page only.
When using {{request.path}}
or {{request.get_full_path}}
for the url like:
<a href="{{ request.path }}" class="btn lang-btn {% ifequal request.LANGUAGE_CODE lang_code %}selected{% endifequal %}">{{lang_code|lang_name}}</a>
It doesn't include the i18n url patterns..
Is there any way for directing current url with request.path??
TARGET
When in /foo/
: /ja/foo/
/en/foo/
/fr/foo/
When in /bar/
: /ja/bar/
/en/bar/
/fr/bar/
Thanks in advance!