Thursday, October 6, 2011

Get correct link to translated version of given node

<?php
$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>';?>

No comments:

Post a Comment