我想在更改Drupal网站上的语言时将用户重定向到主页。 这有可能吗?
答案 0 :(得分:1)
您应该以会话当前语言存储用户,如果更改,则重定向到首页,然后设置为此会话更改语言。
在你的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.
}
}
答案 1 :(得分:1)
在drupal 6中写入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('');
}
}