I've set up a multilanguage site in Drupal 7. In a template I need to add a link to a specific content node. This node has translations and path aliases like so:

node/42 = pathalias_de (german version)
node/43 = pathalias_en (english version)

In the template I'd like to call url() to get the link to the aliased version of the content node in the current language.

On the german page it should link to /de/pathalias_de on the english page to /en/pathalias_en

I've tried several variations, like calling the nid, calling the alias, passing the current language object to url().

Is this something url() should be able to do or do I need a different function? Thanks!

8 Answers 8


After looking at the source of the "Content translation" module I've come up with this solution:

    global $language;
    $translations = translation_path_get_translations("node/42");
    Returns the paths of all translations of a node, based on its Drupal path:
    array(2) {
        ["de"]=>string(7) "node/42"
        ["en"]=>string(7) "node/43"
    print l(t('Link Title'), $translations[$language->language]); //l() will return the alias to node/42

This will output the link to the correct node alias. Works and isn't overly complicated - still wonder if there's a function that already does this.

  • 2
    Or use $translations = translation_path_get_translations(drupal_get_normal_path("pathalias_de","de")); to search for the alias instead of node id, it's more flexible. You have to pass the correct language though.
    – Dooderoo
    Feb 27, 2014 at 8:15
global $language;

$translation_node = translation_path_get_translations("42");

$nid = $translation_node[$language->language]->nid;

$path = "node/{$nid}";
  • 2
    Welcome to Drupal Answers! Whilst this may theoretically answer the question, it would be preferable to include the essential explanations along with your code.
    – Mołot
    Nov 24, 2014 at 9:20

Take a look at drupal_get_path_alias fuction

Given an internal Drupal path, return the alias set by the administrator.

If no path is provided, the function will return the alias of the current page.


$path: An internal Drupal path.

$path_language: An optional language code to look up the path in.

As you can make out it takes a path_language parameter. So you could find out the current language and then pass on to this function.

Or simply use Multilink module

  1. Designed for multi-language sites. Especially relevant for sites where not all content is available in all languages, or may be made available (translated) at a later time.
  2. Allows you to easily create in-content links to other nodes, and those links automatically update to point to a suitable translated version of referenced nodes, when available.
  • 1
    drupal_get_path_alias() won't search for translations of a given node, just for aliases already in the given language. I found another workaround, see my answer below.
    – Dooderoo
    Feb 26, 2014 at 12:00

None of the above answers seem to make correct use of i18n_path. If you want to link to the translated node you should simply enable the i18n_path module and format the path thus,

drupal_get_path_alias('node/'.$node->nid, $node->language);

You should probably use the link function. It allows you to pass the language as a parameter and it's the appropriate function to create a link with Drupal.

  • l() uses url() internally so it doesn't matter in this case.
    – Dooderoo
    Feb 26, 2014 at 11:24

Using Translation Redirect you can link to nodes with language prefix.

This is what it says:

The Translation redirect module redirects anonymous users (including web crawlers) to the translation of the page in the requested language, if it exists, using a 301 redirect code. For example, if the request is for /de/node/23 and node/23 corresponds to an English page, the user will be redirected to the German translation of the English node if it exists. If the translation does not exist, then the source node content is displayed.

For example if nid 22 is for English version and it has French and German ones then you can simply link to them as fr/node/22 and de/node/22. This 22 can also be any nid of the translated version.

If particular translation is not found for example if you've not added for Japanese, then ja/node/22 will give 404 for Anonymous users.


To get the correct prefix path, I use:

$node_url = url(drupal_get_path_alias('node/' . $row->nid));

The drupal_get_path_alias() return only the alias, the url() is the one that add the prefix ("en/").


I used the below code snippet to fetch translation node path in a node page without a node load.

$current_path = current_path();
$tanslation_path = translation_path_get_translations(drupal_get_normal_path($current_path, '---TRANS LANGUAGE---'));
$node_path = url($tanslation_path['---TRANS LANGUAGE---'], array('language' => (object)array('language' => '---TRANS LANGUAGE---')));
$alias_path = drupal_get_path_alias($node_path);

First you have to get the current path and pass this to translation_path_get_translations() or as specified above with translation language code. Then get the alias from its system path.

I used this in hook_preprocess_html() and works fine for me. Hope this helps.

Your Answer

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

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