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!

1
  • Try Internationalization module
    – monymirza
    Nov 16, 2012 at 4:47

3 Answers 3

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.

1
  • This should be the accepted answer. Apr 4, 2016 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));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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