I maintain a large multilingual Drupal site where content is available in 14 different languages. On the whole, the content is translated in to all languages but an increasing number of pages are region specific and don't have a translation available. We have recently moved from a hacky custom language switcher to the core Language Switcher Block. However, the core behaviour for pages that don't have a full translation set is to unset() links to the 'missing' languages. I feel that for those pages with a limited language switcher give a false impression of the languages catered for on our site.
I want to display all languages in the switcher block but link to the homepage when a translation is missing. I see I can achieve this by altering the core translation.module a little (see below) but obviously I don't want to edit core if I don't have to!
function translation_translation_link_alter(&$links, $path) {
if ($paths = translation_path_get_translations($path)) {
foreach ($links as $langcode => $link) {
if (isset($paths[$langcode])) {
// Translation in a different node.
$links[$langcode]['href'] = $paths[$langcode];
}
else {
// No translation in this language, or no permission to view.
// *** PG: I don't want to remove the link but instead point to the homepage for that language ***
// unset($links[$langcode]);
$links[$langcode]['href'] = '<front>';
// *** End of hack ***
}
}
}
}
Can anyone suggest a way to use the magic of hooks to override this functionality in a mini custom module?
Cheers
Paul
Comments
Hi Paul, here is a simple
Hi Paul, here is a simple code ...
works ok for me.. hope it helps!
regards