Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Get correct link to translated version of given node
I am using this snippet on a multilingual enabled site to get the correct translated link of a given node that is hardcoded in a block.
$nodepath is the path to the node of which you want to have a link to the translated version in the current language.
$nodepath = "node/106";
$languagepaths = translation_path_get_translations($nodepath);
$currentlanguage = i18n_get_lang();
$path = $languagepaths[$currentlanguage];
if (preg_match('/^node/',$path)) {
if ( $currentlanguage == "en" ) {
$path = drupal_get_path_alias($path, $currentlanguage);
} else {
$path = $currentlanguage ."/". drupal_get_path_alias($path, $currentlanguage);
}
} else {
$path = $nodepath;
}
echo '<a href="/'. $path. '">Link</a>';
Comments
Get correct link to translated node or term
I use this helper function to generate a group of language switcher links for all enabled languages for a miltilingual site.
It handles both node translations and the translation of multilingual vocabularies with translatable terms.
even simpler
was wrong --
d7?
this is good for d6. any for d7? thanks
//trying to answer one question for each one that i make.
//this way, drupal will be more friendly and strong