I have checked the issue queue and there are a number of issues related to i18n, but I could not find this exact issue. The issues is as follows -

I have a multilingual site - English is the default language (no prefix) and Spanish is the other language (prefix is "es"). I also have Apache Solr search, which does not filter by language by default. Consider that user is in the Spanish site and does a search. All matching nodes from English and Spanish are shown. The urls of the English nodes come as "node/[nid]" i.e. non-aliased. If user clicks a English node title, he is properly redirected to the Spanish translation if the translation of the node is available. Problem is when the English node does not have a translation. Then it leads to a "page not found". I thought this is as per design, but checking the module's code I found that the module actually redirects to the proper node after changing the global $language. So this should work; but it does not. I did some digging in and found that adding the following line after line 161 fixes the issue -

$options['prefix'] = $language->prefix;

Now, question is - am I doing it right, or I have misunderstood or mis-configured something? (Of course I know that I should create a patch rather than editing the module, but want to confirm whether this is really an issue)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fabianderijk’s picture

I've created a patch for this issue

fabianderijk’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: different_language_redirect-1710156-1.patch, failed testing.

fabianderijk’s picture

FileSize
553 bytes

Readded the patch with correct working paths

fabianderijk’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: different_language_redirect-1710156-4.patch, failed testing.

fabianderijk’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: different_language_redirect-1710156-4.patch, failed testing.

Jose Reyero’s picture

I've found a similar issue. The problem seems to happen when trying to redirect to a language that has no prefix.

Example: /es/node/1
The node is English (no prefix) so it should redirect to /node/1
but instead it keeps redirecting (endless loop) to /es/node/1

I've traced the issue to the following lines in locale_language_url_rewrite_url(), which as we can see, if the language to redirect to has no prefix, doesn't override the original one.

      case LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX:
        if (!empty($options['language']->prefix)) {
          $options['prefix'] = $options['language']->prefix . '/';
        }
        break;

This patch fixed the issue for me, it's basically the same as the one proposed by @fabianderijk just bit more generic.

kmonty’s picture

Title: Issue related to redirection to a node with a different language from the current language » Redirection to a node with a different language from the current language fails when default language has no prefix
Version: 7.x-1.5 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

I had this exact problem and patch #9 solved the issue.

kmonty’s picture

Title: Redirection to a node with a different language from the current language fails when default language has no prefix » Redirection to a node with a different language from the current language fails when default language has no path prefix

Further clarifying title.

kmonty’s picture

Title: Redirection to a node with a different language from the current language fails when default language has no path prefix » Redirection to a node with a different language from the current language fails when destination language has no path prefix
BarisW’s picture

Status: Reviewed & tested by the community » Needs review

This need more reviewers. Just one reviewer isn't enough to set it to RTBC.

m.abdulqader’s picture

Patch needs to be rerolled

m.abdulqader’s picture

Simon Georges’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm I had the same issue and this patch fixed it.

i-trokhanenko’s picture

Patch #15 fixes redirection issue for me. +1 RTBC
Thanks!