如何在Drupal 6中以用户/注册表格添加语言切换器

时间:2011-04-05 18:48:50

标签: drupal drupal-6 internationalization registration

我正在尝试以用户/注册形式添加语言设置(例如在用户编辑中),但我没有成功通过Google找到解决方案。

如何在注册表单中添加用户的语言设置?

提前致谢

1 个答案:

答案 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;
    }
}