2014-04-02 08:46:34 +08:00
|
|
|
import warnings
|
|
|
|
|
2011-06-16 01:29:10 +08:00
|
|
|
from django.conf import settings
|
2012-08-03 08:03:52 +08:00
|
|
|
from django.conf.urls import patterns, url
|
2011-06-16 01:29:10 +08:00
|
|
|
from django.core.urlresolvers import LocaleRegexURLResolver
|
2014-04-02 08:46:34 +08:00
|
|
|
from django.utils import six
|
|
|
|
from django.utils.deprecation import RemovedInDjango20Warning
|
2011-06-16 01:29:10 +08:00
|
|
|
|
2013-10-31 23:42:28 +08:00
|
|
|
|
2011-06-16 01:29:10 +08:00
|
|
|
def i18n_patterns(prefix, *args):
|
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
2014-04-03 23:03:31 +08:00
|
|
|
if isinstance(prefix, six.string_types):
|
2014-04-02 08:46:34 +08:00
|
|
|
warnings.warn(
|
|
|
|
"Calling i18n_patterns() with the `prefix` argument and with tuples "
|
|
|
|
"instead of django.conf.urls.url() instances is deprecated and "
|
|
|
|
"will no longer work in Django 2.0. Use a list of "
|
|
|
|
"django.conf.urls.url() instances instead.",
|
|
|
|
RemovedInDjango20Warning, stacklevel=2
|
|
|
|
)
|
|
|
|
pattern_list = patterns(prefix, *args)
|
|
|
|
else:
|
|
|
|
pattern_list = [prefix] + list(args)
|
2011-06-16 01:29:10 +08:00
|
|
|
if not settings.USE_I18N:
|
|
|
|
return pattern_list
|
|
|
|
return [LocaleRegexURLResolver(pattern_list)]
|
|
|
|
|
2005-11-04 12:59:46 +08:00
|
|
|
|
2014-04-02 08:46:34 +08:00
|
|
|
urlpatterns = [
|
2012-08-03 08:03:52 +08:00
|
|
|
url(r'^setlang/$', 'django.views.i18n.set_language', name='set_language'),
|
2014-04-02 08:46:34 +08:00
|
|
|
]
|