Internationalization (i18n) functions

1.

echo _i18n_get_original_path();

Gets the path of the current page. For this one it is: en/internationalization-i18n-functions

2.

echo i18n_get_normal_path(_i18n_get_original_path());

This function outputs the most basic path, meaning: node/, user/. For this page it is: node/9.

i18n_get_normal_path takes a path alias as an argument.

3.

echo i18n_path( i18n_get_normal_path(_i18n_get_original_path()),'de')

This combination is extremely useful. It allows us to create a link to a page in another language. Example:

4.

echo i18n_path('node/9','de'); //outputs "de/internationalization-i18n-functions"

Note: This function will not retrieve the alias of the German translation. To do so, you need to know the nid of the German translation. Suppose it's node/11, then you could call   i18n_path('node/11','de'); which would return "de/internationalization-i18n-funkcionen".

5. What if you needed a path without a language prefix?

One way would calling i18n_path('node/9',''). The only shortcoming of this solution is the slash in front. But to find a solution to this problem, it is enough to have a look at how i18n_path is defined.

<?php
function i18n_path($path, $lang) {
  if (!$path || $path == i18n_frontpage($lang)) {
    return $lang;
  } elseif($alias = drupal_lookup_path('alias', $path)) {
          if($prefix = i18n_get_lang_prefix($alias)) {
      // This alias will be valid only if it has the same language
            return ($prefix == $lang) ? $alias : $lang.'/'.$path;
          } else { // Alias without language prefix
            return $lang.'/'.$alias;
          }
  } else { // Alias for language path will be searched later
    return $lang.'/'.$path;  
  }
}

We can see that good old drupal_lookup_path() will do the magic.