From 5a1580c4d54c2d630a2dd0883b0628c11fc4ec65 Mon Sep 17 00:00:00 2001 From: Oleg Lavrovsky Date: Wed, 19 Apr 2017 18:52:30 +0200 Subject: [PATCH] Language switching within context --- publichealth/home/templates/tags/language.html | 2 +- publichealth/home/templatetags/navigation.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/publichealth/home/templates/tags/language.html b/publichealth/home/templates/tags/language.html index 6e7dfd3..a9c465f 100644 --- a/publichealth/home/templates/tags/language.html +++ b/publichealth/home/templates/tags/language.html @@ -1,3 +1,3 @@ {% for lang in languages %} - {{ lang.title }} + {{ lang.title }} {% endfor %} diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index be7a954..523f310 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -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'], - } \ No newline at end of file + }