From 3a8ddd7afd823892a6a0fae2dc1b8931abe496ba Mon Sep 17 00:00:00 2001 From: Oleg Lavrovsky Date: Fri, 3 Mar 2017 18:13:31 +0100 Subject: [PATCH] Language switcher tag --- publichealth/home/templates/tags/language.html | 3 +++ publichealth/home/templatetags/navigation.py | 14 ++++++++++++++ publichealth/templates/header.html | 11 ++++++----- readme.md | 4 ++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 publichealth/home/templates/tags/language.html create mode 100644 publichealth/home/templatetags/navigation.py diff --git a/publichealth/home/templates/tags/language.html b/publichealth/home/templates/tags/language.html new file mode 100644 index 0000000..dc5963f --- /dev/null +++ b/publichealth/home/templates/tags/language.html @@ -0,0 +1,3 @@ +{% for lang in languages %} + {{ lang.title }} +{% endfor %} diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py new file mode 100644 index 0000000..1072742 --- /dev/null +++ b/publichealth/home/templatetags/navigation.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from django import template +from django.utils import translation + +register = template.Library() + +# Language switcher +@register.inclusion_tag('home/templates/tags/language.html', takes_context=True) +def language_switcher(context): + return { + 'languages': [ { 'code': 'de', 'title': 'De' }, { 'code': 'fr', 'title': 'Fr' } ], + 'currentlangcode': translation.get_language(), + 'request': context['request'], + } diff --git a/publichealth/templates/header.html b/publichealth/templates/header.html index 1a3d204..ef56726 100644 --- a/publichealth/templates/header.html +++ b/publichealth/templates/header.html @@ -1,18 +1,19 @@ +{% load wagtailcore_tags navigation %} +