Skip to content

Commit

Permalink
Generalize language switcher via custom template tag #72
Browse files Browse the repository at this point in the history
  • Loading branch information
4lm committed Aug 15, 2019
1 parent d2b05a3 commit 67258bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
17 changes: 10 additions & 7 deletions templates/stemp_abw/navigation_base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{% load i18n %}
{% load language_tags %}
{% language_store as languages %}
{% get_current_language as current_language %}

<!-- MAIN NAVIGATION START -->
<nav>
<div class="title-bar" id="nav-container" data-responsive-toggle="simple-menu" data-hide-for="medium">
Expand All @@ -18,13 +22,12 @@
<form id="set-lang-form" action="{% url 'stemp_abw:set_language' %}" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}">
<select class="menu dropdown" name="language">
{% get_current_language as LANGUAGE_CODE %}
<option value="de"{% if LANGUAGE_CODE == "de" %} selected{% endif %}>
Deutsch (de)
</option>
<option value="en"{% if LANGUAGE_CODE == "en" %} selected{% endif %}>
English (en)
</option>
{% for language in languages %}
{% get_language_info for language as lang %}
<option value="{{ language }}" {% if current_language == language %} selected{% endif %}>
{{lang.code}} ({{ lang.name_local }})
</option>
{% endfor %}
</select>
</form>
</div>
Expand Down
Empty file added templatetags/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions templatetags/language_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import template
from stemp_abw.app_settings import LANGUAGE_STORE

register = template.Library()


@register.simple_tag
def language_store():
return LANGUAGE_STORE

0 comments on commit 67258bb

Please sign in to comment.