I have a multilanguage site in Drupal 7.

The language negotiation is based on URL. I have got translated content, so when I visit www.example.com/this-is-a-news in English, I can change to Spanish using the language switcher and go to www.example.com/esta-es-una-noticia, which is the URL of the translated node. However, I have some URLs which are dynamic, i.e., they are built in-the-fly, for example: www.example.com/this-is-a-news/on-the-fly-parameter...

As the part of the URL /on-the-fly-parameter is completely dynamic and can change, and because the translation is a non-Drupal table in the database which is updated independently, I want to hook the language switcher and add the translations of all of these URLs dynamically. How can I achieve this?


I have discovered how to do it.

function MYTEMPLATE_language_switch_links_alter(array &$links, $type, $path) {

 $extract_parameters_URL = explode("/", $_SERVER['REQUEST_URI']);

 $code_altered_url = process_URL_extracts($extract_parameters_URL);

 foreach ($links as $langcode => $link) {

    $links[$langcode]['href'] = $code_altered_url ;

 } // foreach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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