【发布时间】:2011-02-16 01:45:28
【问题描述】:
我想在我的 Drupal 网站上更改语言时将用户重定向到主页。 这有可能吗?
【问题讨论】:
我想在我的 Drupal 网站上更改语言时将用户重定向到主页。 这有可能吗?
【问题讨论】:
您应该将用户的当前语言存储在会话中,然后如果更改,则重定向到首页,然后设置为该会话更改的语言。
在您的 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.
}
}
【讨论】:
code function salamanderskins_preprocess_page($vars, $hook) {全球$语言; $currentlanguage = isset($_SESSION['currentlanguage']) ? $_SESSION['currentlanguage'] : $language->language; if ($language->language != $currentlanguage) { drupal_goto(url().'/'.$language->language); //转到当前语言版本,如果您使用SITEURL{languagecode}版本,否则将其更改为适当的。 } $_SESSION['currentlanguage'] = $language->language; }
drupal_goto() 不接受语言代码 (D7)。
在 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('');
}
}
【讨论】: