Language fallback for placeholders #449

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

Comments

Projects
None yet
4 participants
@lasarux
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@ojii

ojii May 26, 2010

Collaborator

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

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@lasarux

lasarux May 28, 2010

Contributor

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

Contributor

lasarux commented May 28, 2010

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

@ojii

This comment has been minimized.

Show comment
Hide comment
@ojii

ojii May 28, 2010

Collaborator

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.

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@benzkji

benzkji Jun 30, 2011

Contributor

could be done in CMS_PLACEHOLDER_CONF, for each placeholder seperatly:

CMS_PLACEHOLDER_CONF = {
    'header_image':{
        'plugins': ('ImagePlugin'),
        'name': ugettext("Header"),
        'language_fallback': True
}
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@ojii

ojii Jun 30, 2011

Collaborator

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

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@yakky

yakky Jun 28, 2012

Contributor

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

Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment