我正在尝试以用户/注册形式添加语言设置(例如在用户编辑中),但我没有成功通过Google找到解决方案。
如何在注册表单中添加用户的语言设置?
提前致谢
答案 0 :(得分:1)
我还没有找到直接解决方案。
所以似乎需要一个小的自定义模块。
我从hook_user
模块中复制了locale
的实现,并略微修改了它
所以创建自定义模块,这个钩子就足够了。
/**
* Implementation of hook_user().
*/
function yourmodulename_user($op, &$edit, &$account, $category = NULL) {
global $language;
// If we have more then one language and either creating a user on the
// admin interface or edit the user, show the language selector.
if ($op == 'register') {
$languages = language_list('enabled');
$languages = $languages[1];
// If the user is being created, we set the user language to the page language.
$user_preferred_language = $user ? user_preferred_language($user) : $language;
$names = array();
foreach ($languages as $langcode => $item) {
$name = t($item->name);
$names[$langcode] = $name . ($item->native != $name ? ' ('. $item->native .')' : '');
}
$form['locale'] = array(
'#type' => 'fieldset',
'#title' => t('Language settings'),
'#weight' => 1,
);
$form['locale']['language'] = array(
'#type' => (count($names) <= 5 ? 'radios' : 'select'),
'#title' => t('Language'),
'#default_value' => $user_preferred_language->language,
'#options' => $names,
'#description' => t("This account's default language for e-mails."),
);
return $form;
}
}