Problem/Motivation
On a multi-lingual site, we found that if you change the language of a node from non-English to English, the node url updates properly, but the postback does not use the correct language prefix when you redirect to the new location. Instead, it redirects to the old-language prefix.
Example:
French node created at domain.com/fr/node-title
Edit node, change language to English, click Save. You are now sent to:
domain.com/fr/node-title
where you get a 404 because the actual url is now domain.com/node-title
Proposed resolution
The problem happens because the english language does not have a language prefix define. At the bottom of locale_language_url_rewrite_url in locale.inc, there is the following case statement:
case LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX:
if (!empty($options['language']->prefix)) {
$options['prefix'] = $options['language']->prefix . '/';
}
break;
Because English doesn't have a prefix, this results in $options['prefix'] remaining 'fr/' (or whatever other non-english language you're working with). And that ends up giving you a 404 when you get redirected back to the bad path.
The fix is simple:
case LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX:
if (!empty($options['language']->prefix)) {
$options['prefix'] = $options['language']->prefix . '/';
} else {
$options['prefix'] = '';
}
break;
Comments
Comment #1
Gorgees Maleel CreditAttribution: Gorgees Maleel commentedGood topic, well done.www.soran.edu.iq