url() with language does not return url_alias in specified language
hass - October 11, 2008 - 16:11
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | base system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | by design |
Jump to:
Description
We tried to get the aliased URL with url('node/'. $source_node->nid, array('language' => $source_node->language)), but we only get the internal URL with base_path.
I verified that the URL for node/11 have an alias named "impressum" and the node is shown on the site with "de/impressum". If I switch to the English version of the node/64 I get "en/imprint". Therefore from DB side it looks all correct only the url() behaves wrong and does not return the correct URL. I expected to get on the English node when I call URL with DE language the alias to the German node!?
This seems to be a bug to me. Could someone please help?

#1
I doubt this code has changed in Drupal 7, so moving it there for additional eyes.
#2
Let's say you have two nodes:
- node/11 is a German node, with a path alias pointing to "de/impressum"
- node/64 is an English node (translation of node/11), with a path alias pointing to "en/imprint"
In that case, if
$languages = language_list(), here is what you should see:<?phpurl('node/11', array('language' => $languages['de'])) => 'de/impressum'
url('node/11', array('language' => $languages['en'])) => 'node/11'
url('node/64', array('language' => $languages['de'])) => 'node/64'
url('node/64', array('language' => $languages['en'])) => 'en/imprint'
?>
This is because path aliases are *per language*, and that aliases generated by nodes are in the language of their node by default.
Are you seeing anything different?
#3
Oh, and you should use:
<?php$languages = language_list();
url('node/'. $source_node->nid, array('language' => $languages[source_node->language]));
?>
instead of:
<?phpurl('node/'. $source_node->nid, array('language' => $source_node->language));
?>
Because url() expects a language object, not a language code here.
#4
Closing this, 'language' should be a language object, not a language code, period.
#5
THX for your help. I will try again.