0

If I'm using multiple languages on the site with path prefixing, is there a quick way to get a system path for the current language?

For example, if the current language is English, and I'm interested getting the English path for 'user/password', what function call (or small number of lines) will return 'en/user/password'?

The following doesn't seem to work; it returns nothing:

drupal_lookup_path('alias', 'user/password', $language->language);
2
  • What's the value of $language->language?
    – Ollie
    Jul 8, 2014 at 17:11
  • If English is the current interface language, then that would be "en" as the "language" property of the global object is the language code.
    – colan
    Jul 8, 2014 at 20:23

1 Answer 1

0

The internal path is same for all languages,though you can set different alias for different languages. From your question it seems that you want to get the path with language prefix not the alias, if so then I don't think there is any function that will return the path with language prefix.

Since you can get the language using $language->language you can write a custom function as follows.

function custom_lookup_path($action, $path = '', $path_language = NULL){
   global $language;
   if(empty($path_language)){
      $path_language=$language->language;
   }
   if(!empty($language->prefix)){
      $path = $language->prefix.'/'.drupal_lookup_path($action, $path , $path_language);
   }
   else{
      $path = drupal_lookup_path($action, $path , $path_language);
   }
   return $path
}
2
  • $language->prefix would be better as the language code isn't necessarily the same as the prefix.
    – colan
    Jul 8, 2014 at 20:28
  • @colan yes, you're correct
    – msmani
    Jul 9, 2014 at 4:31

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.