网 站是双语中英文,使用模块是i18n,当设置中文为默认语言时,在语言编辑中要去掉前缀prefix,英文编辑中要添加前缀en;这样设置后默认语言还是 没有转换过来,还是英文。通过查看htdocs\sitesname\includes\language.inc文件,在语言转换时 language_initialize()该方法返回了调用哪一种语言。
function language_initialize() {
global $user;
// Configured presentation language mode.
$mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
// Get a list of enabled languages.
$languages = language_list('enabled');//启用的语言
$languages = $languages[1];
switch ($mode) {//admin/settings/language/configure语言协定,选择用来判定网站用何种语言显示的机制。
case LANGUAGE_NEGOTIATION_NONE:
return language_default();//返回的是后台语言设置中默认语言对象
case LANGUAGE_NEGOTIATION_DOMAIN:
foreach ($languages as $language) {
$parts = parse_url($language->domain);
if (!empty($parts['host']) && ($_SERVER['HTTP_HOST'] == $parts['host'])) {
return $language;
}
}
return language_default();
case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
case LANGUAGE_NEGOTIATION_PATH:
// $_GET['q'] might not be available at this time, because
// path initialization runs after the language bootstrap phase.
$args = isset($_GET['q']) ? explode('/', $_GET['q']) : array();
$prefix = array_shift($args);
// Search prefix within enabled languages.
foreach ($languages as $language) {
if (!empty($language->prefix) && $language->prefix == $prefix) {
// Rebuild $GET['q'] with the language removed.
$_GET['q'] = implode('/', $args);
return $language;
}
}
if ($mode == LANGUAGE_NEGOTIATION_PATH_DEFAULT) {
// If we did not found the language by prefix, choose the default.
return language_default();
}
break;
}
//当代码走到这里时我发现,语言的转换与登录用户的账户语言有关。打开USERS表查看,//,这里的语言原来默认为en如果改为默认语言中文zh-hans,则语言跳转就正常了,另外对默认语言设置后,一定要清空缓存,不然不能立刻看到设置的效果。
// User language.
if ($user->uid && isset($languages[$user->language])) {
return $languages[$user->language];
}
//根据浏览器中设置的本地语言来让网站语言同步。
// Browser accept-language parsing.
if ($language = language_from_browser()) {
return $language;
}
// Fall back on the default if everything else fails.
return language_default();
}
希望对有此相同问题的人有帮助。