Skip to content

Commit

Permalink
Add fall-back function for URL language switch, fixes Alfanous-team#456
Browse files Browse the repository at this point in the history
  • Loading branch information
sneetsher committed May 9, 2017
1 parent 3efcbdf commit da8f3af
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/alfanous-django/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
from django.views.generic import RedirectView
from django.conf import settings

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
Expand All @@ -18,6 +20,12 @@
url(r'^(?P<unit>\w{3,15})/', 'wui.views.results'),
)

# Fall-back for non-supported languages from URL swich: xx-YY to xx to default (en)
urlpatterns += patterns('',
url(r'^(?P<lang>[a-z]{2})-[A-Za-z]{2}/(?P<path>.*)$', RedirectView.as_view(url='/%(lang)s/%(path)s',query_string=True)),
url(r'^[a-z]{2}/(?P<path>.*)$', RedirectView.as_view(url='/{}/%(path)s'.format(settings.LANGUAGE_CODE),query_string=True)),
)

# 404 not found handler

handler404 = 'wui.views.custom_404'

0 comments on commit da8f3af

Please sign in to comment.