You are here

function locale_user in Drupal 6

Same name and namespace in other branches
  1. 4 modules/locale.module \locale_user()
  2. 5 modules/locale/locale.module \locale_user()

Implementation of hook_user().

File

modules/locale/locale.module, line 202
Add language handling functionality and enables the translation of the user interface to languages other than English.

Code

function locale_user($type, $edit, &$user, $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 (variable_get('language_count', 1) > 1 && ($type == 'register' && user_access('administer users') || $type == 'form' && $category == 'account')) {
    $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[check_plain($langcode)] = check_plain($name . ($item->native != $name ? ' (' . $item->native . ')' : ''));
    }
    $form['locale'] = array(
      '#type' => 'fieldset',
      '#title' => t('Language settings'),
      '#weight' => 1,
    );

    // Get language negotiation settings.
    $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
    $form['locale']['language'] = array(
      '#type' => count($names) <= 5 ? 'radios' : 'select',
      '#title' => t('Language'),
      '#default_value' => check_plain($user_preferred_language->language),
      '#options' => $names,
      '#description' => $mode == LANGUAGE_NEGOTIATION_PATH ? t("This account's default language for e-mails, and preferred language for site presentation.") : t("This account's default language for e-mails."),
    );
    return $form;
  }
}