Smarter language checker
This commit is contained in:
parent
9e32a63db6
commit
d076cb4587
1 changed files with 6 additions and 3 deletions
|
@ -7,11 +7,14 @@ register = template.Library()
|
|||
# Language switcher
|
||||
@register.inclusion_tag('tags/language.html', takes_context=True)
|
||||
def language_switcher(context):
|
||||
url = context['page'].url
|
||||
url = context['page'].url.split('/')
|
||||
if len(url) > 2 and len(url[1]) == 2:
|
||||
url[1] = '$lang$'
|
||||
url = '/'.join(url)
|
||||
return {
|
||||
'languages': [
|
||||
{ 'code': 'de', 'title': 'De', 'url': url.replace('/fr/','/de/') },
|
||||
{ 'code': 'fr', 'title': 'Fr', 'url': url.replace('/de/','/fr/') }
|
||||
{ 'code': 'de', 'title': 'De', 'url': url.replace('$lang$','de') },
|
||||
{ 'code': 'fr', 'title': 'Fr', 'url': url.replace('$lang$','fr') }
|
||||
],
|
||||
'currentlangcode': translation.get_language(),
|
||||
'request': context['request'],
|
||||
|
|
Loading…
Reference in a new issue