开发者

How to add Language switcher in user/register form in Drupal 6

开发者 https://www.devze.com 2023-02-22 01:24 出处:网络
I am trying to add Language settings in user/register form (like in user edit), but I haven\'t had any success finding a solution through Google.

I am trying to add Language settings in user/register form (like in user edit), but I haven't had any success finding a solution through Google.

Any ideas how I can add a开发者_运维知识库 user's language settings in the registration form?

Thanks in advance


I haven't managed to find a direct solution as well.
So it seems that a small custom module will be required. I copied the implementation of hook_user from the locale module and slightly modified it.
So create your custom module and this hook will be enough.

/**
 * 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;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消