Hello,

I have the latest stable of all the following modules
Content Translation
Locale
Internationalization
Multilingual Content
i18n_redirect

and Global Redirect.

When I enable "Language Path Checking" I get an endless redirect loop.

Why I want to enable that? Because it seems i18n_redirect is not working. Language prefixed paths with no translated content are not redirecting to the one that is available for example
http://proofreadbot.com/proofreading/188055

Is in English, when I do es/proofreading/188055 it should redirect to http://proofreadbot.com/proofreading/188055 but it leaves the es prefix.

I don't have a language key configured for the default "en" here, but on another site where I have English as the default language with a language key "en" global redirect with language checking works.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

Status: Active » Needs review
FileSize
553 bytes

I have a very similar issue. I have 2 languages enabled:

ie (default, no path prefix)
en (path prefix = 'en')

If I create a node that is set to 'ie' (the default language), I get a redirect loop - visiting /thenode shows the node. However, visiting /en/thenode gives a redirect loop.

If I create a node that is set to 'en' (a secondary language with a prefix), everything works as expected - visiting /en/thenode shows the node, and visiting /thenode redirects to /en/thenode.

The problem seems to be in the following block of code:

        // If there is no translation, change the language to fit the content
        else {
          $node = node_load($matches[1]);
          // Check the node has a language set, that it isn't "NONE" (und) and that it dosn't match the site's current language
          if (isset($node->language) && $node->language != LANGUAGE_NONE && $node->language != $language->language) {
            $all_languages = language_list();
            // TODO: Is it possible to get here with a node in a language not in $all_languages?
            // Change the global $language's prefix, to make drupal_goto()
            // follow the proper prefix
            $options['language'] = $language = $all_languages[$node->language];
            globalredirect_goto('node/' . $node->nid . $matches[2], $options);
          }
        }

globalredirect_goto is passed $options, which already has $options['prefix'] set to the current interface language. This means constantly tries to redirect to /en/thenode. The comment in the code indicates that by setting $options['language'], the goto should use the proper prefix. This is incorrect. You need to set $options['prefix'] to do that. The attached patch resolves my redirect loop, and gets the language redirection working as expected.

giorgio79’s picture

Status: Needs review » Reviewed & tested by the community

WOW, THAT IS AWESOME. SORRY FOR THE CAPS, BUT I AM VERY HAPPY :P

Installed patch, works as expected. Fantastic.

mrfelton’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
681 bytes

Previous patch was slightly wrong. We should not set $options['prefix'] at all This is determined by drupal_goto using the prefix in $options['language']. We need to ensure that prefix is not set at all. Patch updated.

giorgio79’s picture

Status: Needs review » Reviewed & tested by the community

Yep, works for me. Very nice.

giorgio79’s picture

Status: Reviewed & tested by the community » Needs work

Spoke too soon. Found a small issue whereby content that is language neutral (und) the node still gives an endless loop. If $node->language is set it works fine.

giorgio79’s picture

Status: Needs work » Reviewed & tested by the community

Ok the patch works, I was getting an endless loop because of this bug in Services #1668422: Default language to undefined on node if no language is set. the language field was completely empty...If I set it to und the patch works fine.

jm.federico’s picture

Hello

You might want to check #1843500: Wrong usage of prefix in Global Redirect (Patch attached) which fixes prefixes in this module.
It will happen with whatever module you have that uses prefixes, not only i18n.

Cheers

jm.federico’s picture

Status: Reviewed & tested by the community » Needs work

I'm markin this as needs works
Prefixes are more complex than just language selection. Language selection is by far the most common one but not the only one.

This is an example site
http://www.redservi.co/

which uses prefixes to change content and language. It has a module that prepends the country to the language prefix.
2 countries 2 languages
http://www.redservi.co/RD-es
http://www.redservi.co/RD-en
http://www.redservi.co/CO-es
http://www.redservi.co/CO-en

There is a patch in #1843500-3: Wrong usage of prefix in Global Redirect (Patch attached) that changes how globalredirect plays with prefixes.
The real problem is that globalredirect is using the paths in the wrong way. Right now it uses the request path to start all the comparison magic, but we should use the current_path() which doesn't include the prefix.

I have had this issue for a while now, and it comes from D6, happened with strongarm and purl module that also uses prefixes.

I'm sorry if I'm being a bi pushy with this but I do thing that this needs addressing.

I make extensive use of prefixes and I haven't been able to use the orignal globalredirect because of this.

If I'm not being clear let me know and I'll try to rephrase things.

Hope you all have an awesome 2013!

jm.federico’s picture

Issue summary: View changes

sdfgsdfg sdfg sdfg sdfg sdfg

devad’s picture

Issue summary: View changes
Status: Needs work » Closed (duplicate)

Patch #3 worked for me. However, better solution is on the way, so I'm closing this as duplicate of #1843500: Wrong usage of prefix in Global Redirect (Patch attached)

Yoa’s picture

The patch in #1843500: Wrong usage of prefix in Global Redirect (Patch attached) didnt work for me while patch #3 from here did work..
using i18n_redirect