Skip to content

Language fallback for placeholders #449

Closed
lasarux opened this Issue Apr 22, 2010 · 6 comments

4 participants

@lasarux
lasarux commented Apr 22, 2010

Currently I'm using this approach. I think this would improve django-cms language fallbacks.

diff --git a/cms/plugin_rendering.py b/cms/plugin_rendering.py
index 221273a..26b12f2 100644
--- a/cms/plugin_rendering.py
+++ b/cms/plugin_rendering.py
@@ -1,6 +1,7 @@
 from cms.utils import get_language_from_request
 from cms import settings
 from cms.utils.placeholder import get_page_from_placeholder_if_exists
+from cms.utils.i18n import get_fallback_languages, get_default_language
 from django.conf import settings as django_settings
 from django.utils.importlib import import_module
 from django.core.exceptions import ImproperlyConfigured
@@ -125,7 +126,15 @@ def render_placeholder(placeholder, context_to_copy):
     from cms.plugins.utils import get_plugins
     context = copy.copy(context_to_copy) 
     request = context['request']
-    plugins = [plugin for plugin in get_plugins(request, placeholder)]
+    lang = get_language_from_request(request)
+    if settings.CMS_LANGUAGE_FALLBACK and lang != get_default_language():
+        fallbacks = get_fallback_languages(lang)
+        for l in fallbacks:
+            plugins = [plugin for plugin in get_plugins(request, placeholder, l)]
+            if plugins:
+                break
+    else:
+        plugins = [plugin for plugin in get_plugins(request, placeholder)]
     page = get_page_from_placeholder_if_exists(placeholder)
     if page:
         template = page.template
@ojii
ojii commented May 26, 2010

I do not think that this should be the default behavior. There should be a way to explicitly enable this for each placeholder.

@lasarux
lasarux commented May 28, 2010

You're right. Add a check here using settings to enable it is easy.

@ojii
ojii commented May 28, 2010

We already have way too many settings, so 'just add another one' will not work. Give me a very good reason to add a setting and prove that it can't be done differently more elegant.

@benzkji
benzkji commented Jun 30, 2011

could be done in CMS_PLACEHOLDER_CONF, for each placeholder seperatly:

CMS_PLACEHOLDER_CONF = {
    'header_image':{
        'plugins': ('ImagePlugin'),
        'name': ugettext("Header"),
        'language_fallback': True
}
@ojii
ojii commented Jun 30, 2011

Once 2.3 feature discussion starts, feel free to bring that up again. For now, all i care about is finally getting 2.2 out

@yakky
yakky commented Jun 28, 2012

Related to general multilingual / language fallback behaviour (documented here: https://github.com/divio/django-cms/wiki/multilingual-behaviour).
I think it deserves a try, while the inherit plugin may be a valid substitude
Created patch + test for further discussion.
TODO: Test for PlaceholderField

@digi604 digi604 closed this in #1903 May 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.