You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

36 lines
1.2 KiB

  1. import warnings
  2. from django.conf import settings
  3. from django.conf.urls import patterns, url
  4. from django.core.urlresolvers import LocaleRegexURLResolver
  5. from django.utils import six
  6. from django.utils.deprecation import RemovedInDjango110Warning
  7. from django.views.i18n import set_language
  8. def i18n_patterns(prefix, *args):
  9. """
  10. Adds the language code prefix to every URL pattern within this
  11. function. This may only be used in the root URLconf, not in an included
  12. URLconf.
  13. """
  14. if isinstance(prefix, six.string_types):
  15. warnings.warn(
  16. "Calling i18n_patterns() with the `prefix` argument and with tuples "
  17. "instead of django.conf.urls.url() instances is deprecated and "
  18. "will no longer work in Django 1.10. Use a list of "
  19. "django.conf.urls.url() instances instead.",
  20. RemovedInDjango110Warning, stacklevel=2
  21. )
  22. pattern_list = patterns(prefix, *args)
  23. else:
  24. pattern_list = [prefix] + list(args)
  25. if not settings.USE_I18N:
  26. return pattern_list
  27. return [LocaleRegexURLResolver(pattern_list)]
  28. urlpatterns = [
  29. url(r'^setlang/$', set_language, name='set_language'),
  30. ]