Language switching within context

This commit is contained in:
Oleg Lavrovsky 2017-04-19 18:52:30 +02:00
parent 63fd774730
commit 5a1580c4d5
2 changed files with 7 additions and 3 deletions

View file

@ -1,3 +1,3 @@
{% for lang in languages %}
<a{% if lang.code == currentlangcode %} class="active"{% endif %} href="/{{ lang.code }}">{{ lang.title }}</a>
<a{% if lang.code == currentlangcode %} class="active"{% endif %} href="{{ lang.url }}">{{ lang.title }}</a>
{% endfor %}

View file

@ -7,8 +7,12 @@ register = template.Library()
# Language switcher
@register.inclusion_tag('tags/language.html', takes_context=True)
def language_switcher(context):
url = context['page'].url
return {
'languages': [ { 'code': 'de', 'title': 'De' }, { 'code': 'fr', 'title': 'Fr' } ],
'languages': [
{ 'code': 'de', 'title': 'De', 'url': url.replace('/fr/','/de/') },
{ 'code': 'fr', 'title': 'Fr', 'url': url.replace('/de/','/fr/') }
],
'currentlangcode': translation.get_language(),
'request': context['request'],
}
@ -59,4 +63,4 @@ def footer_menu(context, parent, calling_page=None):
'calling_page': calling_page,
'menuitems': menuitems_children(parent),
'request': context['request'],
}
}