Language switcher tag
This commit is contained in:
parent
793a052b4f
commit
3a8ddd7afd
4 changed files with 27 additions and 5 deletions
3
publichealth/home/templates/tags/language.html
Normal file
3
publichealth/home/templates/tags/language.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
{% for lang in languages %}
|
||||
<a{% if lang.code == currentlangcode %} class="active"{% endif %} href="/{{ lang.code }}/home">{{ lang.title }}</a>
|
||||
{% endfor %}
|
14
publichealth/home/templatetags/navigation.py
Normal file
14
publichealth/home/templatetags/navigation.py
Normal file
|
@ -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'],
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
{% load wagtailcore_tags navigation %}
|
||||
|
||||
<nav class="navbar-pre navbar-fixed-top">
|
||||
<div class="container">
|
||||
<div class="nav">
|
||||
|
@ -11,8 +13,7 @@
|
|||
<span class="hidden-xs">info@public-health.ch</span></a>
|
||||
</span>
|
||||
<span class="language-nav">
|
||||
<a class="active" href="/de/home">De</a>
|
||||
<a href="/fr/home">Fr</a>
|
||||
{% language_switcher %}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -53,3 +53,7 @@ grunt browser-sync
|
|||
A default browser should open pointing to the default home page.
|
||||
|
||||
Now access the admin panel with the user account you created earlier: http://localhost:3000/admin/
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Issues with migrating database tables in SQLite during development? Try `./manage.py migrate --fake`
|
||||
|
|
Loading…
Reference in a new issue