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?
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.
}
}
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('');
}
}
精彩评论