Website: Add i18n language detection (of browser language) and language

This commit is contained in:
Emanuel Schuetze 2012-07-18 14:18:32 +02:00
parent 8f4970e16c
commit 5521f70289
3 changed files with 8 additions and 4 deletions

View File

@ -98,8 +98,9 @@ TEMPLATE_LOADERS = (
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',

View File

@ -47,7 +47,9 @@
{% get_available_languages as languages %} {% get_available_languages as languages %}
{% for lang_code, lang_name in languages %} {% for lang_code, lang_name in languages %}
{% language lang_code %} {% language lang_code %}
<li {% if LANGUAGE_CODE == lang_code %}class="active"{% endif %}><a href="{{lang_code}}"><i class="icon-flag icon-white"></i> {{ lang_name }}</a></li> <li {% if LANGUAGE_CODE == lang_code %}class="active"{% endif %}>
<a href="{% url home %}"><i class="icon-flag icon-white"></i> {{ lang_name }}</a>
</li>
{% endlanguage %} {% endlanguage %}
{% endfor %} {% endfor %}
</ul> </ul>
@ -125,4 +127,4 @@
</footer> </footer>
</body> </body>
</html> </html>

View File

@ -7,7 +7,8 @@ from django.views.generic import TemplateView
# from django.contrib import admin # from django.contrib import admin
# admin.autodiscover() # admin.autodiscover()
urlpatterns = patterns('', urlpatterns = i18n_patterns('',
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^$', TemplateView.as_view(template_name="home.html"), name='home',), url(r'^$', TemplateView.as_view(template_name="home.html"), name='home',),
url(r'^about/$', TemplateView.as_view(template_name="about.html"), name='about',), url(r'^about/$', TemplateView.as_view(template_name="about.html"), name='about',),
url(r'^about/features$', TemplateView.as_view(template_name="features.html"), name='features',), url(r'^about/features$', TemplateView.as_view(template_name="features.html"), name='features',),