How to get path to current node but of another language?

Available languages:

  • English (URL prefix: en)
  • Polish (default, no URL prefix)

Enabled detection methods:

  • URL (by prefix)
  • Session (parameter: language)
  • Browser
  • Default

I created translation of taxonomy and translations of some basic page nodes. However, none of the following codes work.

drupal_get_path_alias(null, 'en')
drupal_get_normal_path('', 'en')
drupal_get_path_alias('hardcoded-existing-path', 'en')
url(current_path(), array('language'=>'en'))

How to make it work? All internalization modules are enabled.

1 Answer 1


The problem is the lack of a language string / prefix for polish. By this URL detection is skipped.

Look into locale_language_from_url() line 275

   // $_GET['q'] might not be available at this time, because
   // path initialization runs after the language bootstrap phase.
  list($language, $_GET['q']) = language_url_split_prefix(isset($_GET['q']) ? $_GET['q'] : NULL, $languages);
  if ($language !== FALSE) {
    $language_url = $language->language;

If there is no language found in the URL is skips. Now the language detection is by session and so on. The only real option is that all languages you use have a prefix. The only real problem that than occurs is that the homepage would always redirect wich is not that nice for bots. But still better than fall back to language detection you don't want.

Besides that you could mode "default" just below "URL (prefix)" so Drupal won't use the session or the browser. But even this is not reliable from my experience.

  • I set /pl/ prefix for Polish but those functions still do not work. However, links in built-in language selector block are correct. I don't want to use a block. My language selector will be inline and in 2 places. Mar 30, 2015 at 12:47

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.