Commits

Anonymous committed 0ded599 Draft

Added support for DEFAULT_FUNCTION in settings

The DEFAULT_FUNCTION will let projects set the default language
dynamically instead of reverting to LANGUAGE_CODE in settings
which can't be changed at runtime.

  • Participants
  • Parent commits b8ada3a

Comments (0)

Files changed (1)

localeurl/utils.py

             return check.group('locale'), path_info
     return '', path
 
+def default_language():
+    if hasattr(settings, 'DEFAULT_LANGUAGE'):
+        if callable(settings.DEFAULT_LANGUAGE):
+            return settings.DEFAULT_LANGUAGE()
+        else:
+            return settings.DEFAULT_LANGUAGE
+
+    return settings.LANGUAGE_CODE
+
 def supported_language(locale):
     """
     Returns the supported language (from settings.LANGUAGES) for the locale.
     """
     Returns whether the locale is the default locale.
     """
-    return locale == supported_language(settings.LANGUAGE_CODE)
+    return locale == supported_language(default_language())
 
 def locale_path(path, locale=''):
     """
     """
     locale = supported_language(locale)
     if not locale:
-        locale = supported_language(settings.LANGUAGE_CODE)
+        locale = supported_language(default_language())
     if is_locale_independent(path):
         return path
     elif is_default_locale(locale) and not localeurl_settings.PREFIX_DEFAULT_LOCALE: