1

I'd like to insert a link in my node templates that displays when viewing nodes of a particular type (news). That link should lead to the news archive (node/26). Node 26 is a normal drupal page made in swedish (with a menu item and so on). On that page a block is displayed with a viewed list of news items.

There is a translated version of node/26 - translated with normal multi language modules.

What I'd lite for the system is to redirect from node/26 to the english translated version (node/27) if the current users language is english.

I have the module Translation Redirect activated - but it does not redirect.

If a redirect can't be achieved - is there any way that the link function can create the link depending on what the current language is (preferably without if-cases for each language).

Version is Drupal 7.

Thank you very much for any replies!

  • Try Internationalization module – monymirza Nov 16 '12 at 4:47
1

I ended up doing it this way:

$nodepath = "node/26";
$languagepaths = translation_path_get_translations($nodepath);
$currentlanguage = i18n_language()->language;
$path = $languagepaths[$currentlanguage];

if (preg_match('/^node/',$path)) {
    $path = "". drupal_get_path_alias($path, $currentlanguage);
} else {
   $path = $nodepath;
}
1
<?php 
global $language;
$link = url('node/26',array('language' => $language));
?>
<a href="<?php print $link?>">My Page</a>

credit to mojzis solution.

  • This should be the accepted answer. – stefgosselin Apr 4 '16 at 3:35
0

according to the docs it should be enough to do something like this :

global $language;
$link = l('GO THERE','node/26',array('language' => $language));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.