2011-06-16 01:29:10 +08:00
|
|
|
from django.conf import settings
|
2015-08-17 22:45:00 +08:00
|
|
|
from django.conf.urls import url
|
2015-12-30 23:51:16 +08:00
|
|
|
from django.urls import LocaleRegexURLResolver
|
2014-08-12 22:54:42 +08:00
|
|
|
from django.views.i18n import set_language
|
2011-06-16 01:29:10 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2015-08-17 22:45:00 +08:00
|
|
|
def i18n_patterns(*urls):
|
2011-06-16 01:29:10 +08:00
|
|
|
"""
|
|
|
|
Adds the language code prefix to every URL pattern within this
|
|
|
|
function. This may only be used in the root URLconf, not in an included
|
|
|
|
URLconf.
|
|
|
|
"""
|
|
|
|
if not settings.USE_I18N:
|
2015-08-17 22:45:00 +08:00
|
|
|
return urls
|
|
|
|
return [LocaleRegexURLResolver(list(urls))]
|
2011-06-16 01:29:10 +08:00
|
|
|
|
2005-11-04 12:59:46 +08:00
|
|
|
|
2014-04-02 08:46:34 +08:00
|
|
|
urlpatterns = [
|
2014-08-12 22:54:42 +08:00
|
|
|
url(r'^setlang/$', set_language, name='set_language'),
|
2014-04-02 08:46:34 +08:00
|
|
|
]
|