From 23c3405a00b9e082dd2609b64fe3c9abbb4fdda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mart=C3=ADn?= Date: Mon, 7 Sep 2015 21:20:39 +0200 Subject: [PATCH] Added language switcher and fixed main link --- amiibofindr/apps/core/context_processors.py | 15 +++++++++++++ amiibofindr/apps/home/urls.py | 2 +- amiibofindr/settings/base.py | 1 + amiibofindr/templates/_layout.html | 25 +++++++++++---------- amiibofindr/urls.py | 3 ++- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/amiibofindr/apps/core/context_processors.py b/amiibofindr/apps/core/context_processors.py index 9a6c7a8..f9edea0 100644 --- a/amiibofindr/apps/core/context_processors.py +++ b/amiibofindr/apps/core/context_processors.py @@ -18,3 +18,18 @@ def files(request): 'MEDIA_URL': settings.MEDIA_URL, 'STATIC_URL': settings.STATIC_URL, } + + +def i18n(request): + result = [] + for lang_code, name in settings.LANGUAGES: + this = { + 'code': lang_code, + 'name': name, + 'url': request.path.replace(request.LANGUAGE_CODE, lang_code) + } + result.append(this) + + return { + 'LANGUAGES': result + } diff --git a/amiibofindr/apps/home/urls.py b/amiibofindr/apps/home/urls.py index a8d1cb6..1e7e33a 100644 --- a/amiibofindr/apps/home/urls.py +++ b/amiibofindr/apps/home/urls.py @@ -9,5 +9,5 @@ from .views import HomeView urlpatterns = patterns( '', - url(r'^$', HomeView.as_view()), + url(r'^$', HomeView.as_view(), name='redirect'), ) diff --git a/amiibofindr/settings/base.py b/amiibofindr/settings/base.py index b187fd0..86e7a47 100644 --- a/amiibofindr/settings/base.py +++ b/amiibofindr/settings/base.py @@ -95,6 +95,7 @@ TEMPLATES = [ 'amiibofindr.apps.amiibo.context_processors.currencies', 'amiibofindr.apps.core.context_processors.debug', 'amiibofindr.apps.core.context_processors.files', + 'amiibofindr.apps.core.context_processors.i18n', ], }, }, diff --git a/amiibofindr/templates/_layout.html b/amiibofindr/templates/_layout.html index ee8d5b2..2468c1d 100644 --- a/amiibofindr/templates/_layout.html +++ b/amiibofindr/templates/_layout.html @@ -1,6 +1,8 @@ {% load static i18n account %} {% user_display user as user_display %} {% get_current_language as LANGUAGE_CODE %} +{% get_available_languages as languages %} +{% trans 'all' as all_word %} @@ -29,12 +31,12 @@