Commits

Anonymous committed df80822

Fix LOCALEURL_USE_ACCEPT_LANGUAGE = False PREFIX_DEFAULT_LOCALE = True. If user set some default language that we support but want to change to other language.

  • Participants
  • Parent commits a5d7fcf

Comments (0)

Files changed (3)

File localeurl/middleware.py

+# -*- coding: utf-8 -*-
 from django.conf import settings
 import django.core.exceptions
 from django.http import HttpResponsePermanentRedirect
                         request.META.get('HTTP_ACCEPT_LANGUAGE', ''))])
             if accept_langs:
                 locale = accept_langs[0]
-        locale_path = utils.locale_path(path, locale)
-        if locale_path != request.path_info:
+        locale_path = utils.locale_path(path, utils.supported_language(locale))
+        if locale_path != request.path_info:# and localeurl_settings.PREFIX_DEFAULT_LOCALE:
             if request.META.get("QUERY_STRING", ""):
                 locale_path = "%s?%s" % (locale_path,
                         request.META['QUERY_STRING'])
                 locale = request.LANGUAGE_CODE
             except AttributeError:
                 locale = settings.LANGUAGE_CODE
+            else:
+                if not localeurl_settings.USE_ACCEPT_LANGUAGE:
+                    locale = settings.LANGUAGE_CODE
         translation.activate(locale)
         request.LANGUAGE_CODE = translation.get_language()
 

File localeurl/settings.py

+# -*- coding: utf-8 -*-
 import re
 from django.conf import settings
+from django.conf import global_settings
+SUPPORTED_LOCALES = dict(settings.LANGUAGES)
+ALL_LOCALES = dict(global_settings.LANGUAGES)
 
-SUPPORTED_LOCALES = dict(settings.LANGUAGES)
 LOCALES_RE = '|'.join(SUPPORTED_LOCALES)
 PATH_RE = re.compile(r'^/(?P<locale>%s)(?P<path>.*)$' % LOCALES_RE)
+ALL_LOCALES_RE = '|'.join(ALL_LOCALES)
+ALL_PATH_RE = re.compile(r'^/(?P<locale>%s)(?P<path>.*)$' % ALL_LOCALES_RE)
 
 LOCALE_INDEPENDENT_PATHS = getattr(settings, 'LOCALE_INDEPENDENT_PATHS', ())
 

File localeurl/utils.py

+# -*- coding: utf-8 -*-
 from django.conf import settings
+from django.conf import global_settings
 from django.core import urlresolvers
 from django.core import urlresolvers
 from localeurl import settings as localeurl_settings
     Separates the locale prefix from the rest of the path. If the path does not
     begin with a locale it is returned without change.
     """
-    check = localeurl_settings.PATH_RE.match(path)
+    check = localeurl_settings.ALL_PATH_RE.match(path)
     if check:
         path_info = check.group('path') or '/'
         if path_info.startswith('/'):
     """
     Returns the supported language (from settings.LANGUAGES) for the locale.
     """
-    if locale in localeurl_settings.SUPPORTED_LOCALES:
-        return locale
-    elif locale[:2] in localeurl_settings.SUPPORTED_LOCALES:
-        return locale[:2]
+    if locale:
+        if locale in localeurl_settings.SUPPORTED_LOCALES:
+            return locale
+        elif locale[:2] in localeurl_settings.SUPPORTED_LOCALES:
+            return locale[:2]
+        else:
+            return None
     else:
         return None
 
     Generate the localeurl-enabled path from a path without locale prefix. If
     the locale is empty settings.LANGUAGE_CODE is used.
     """
-    locale = supported_language(locale)
+    print '\t in locale_path'
+    #locale = supported_language(locale)
+    print locale
     if not locale:
+        print 'NOT'
         locale = supported_language(settings.LANGUAGE_CODE)
+        print locale
     if is_locale_independent(path):
+        print '=1'
         return path
     elif is_default_locale(locale) and not localeurl_settings.PREFIX_DEFAULT_LOCALE:
+        print '=2'
         return path
     else:
+        print '=3'
         return ''.join([u'/', locale, path])
 
 def locale_url(path, locale=''):