Mladen Danic
Mladen Danic

Reputation: 3669

Drupal - redirection after language change

I want to redirect users to the homepage when the change the language on my Drupal website. Is this at all possible?

Upvotes: 0

Views: 3052

Answers (2)

drupmaster
drupmaster

Reputation: 11

In drupal 6 write in template.php:

function THEMENAME_preprocess_page(&$vars, $hook) {
  global $language;
  $previouselanguage = isset($_SESSION['previouselanguage']) ? $_SESSION['previouselanguage'] : $language->language;
  $_SESSION['previouselanguage'] = $language->language;
  if ($language->language != $previouselanguage) {
    drupal_goto('');
  }
}

Upvotes: 1

Nikit
Nikit

Reputation: 5128

You should store in session current language of user, then if it changed, redirect to front page, then set to this session changed language.
In your template.php:

/**
 * Override or insert variables into the page templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("page" in this case.)
 */
function THEMENAME_preprocess_page(&$vars, $hook) {
  global $language;
  $currentlanguage = isset($_SESSION['currentlanguage']) ? $_SESSION['currentlanguage'] : $language->language;
  if ($language->language != $currentlanguage) {
    drupal_goto(url().'/'.$language->language); //goto current language version, if you use http://SITEURL/{languagecode} version, otherwise change it to appropriate.
  }
}

Upvotes: 1

Related Questions