1.20.x locale.module locale_language_selector_form($user)

Form builder callback to display language selection widget.

See also

locale_form_alter()

Related topics

File

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

Code

function locale_language_selector_form($user) {
  global $language;
  // Get list of enabled languages only.
  $language_options = language_list(TRUE, TRUE, TRUE);

  // If the user is being created, we set the user language to the page language.
  $user_preferred_language = $user->uid ? user_preferred_language($user) : $language;

  // Get language negotiation settings.
  $mode = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_DEFAULT;
  $form['locale'] = array(
    '#type' => 'fieldset',
    '#title' => t('Language settings'),
    '#weight' => 1,
  );
  $form['locale']['language'] = array(
    '#type' => (count($language_options) <= 5 ? 'radios' : 'select'),
    '#title' => t('Language'),
    '#default_value' => $user_preferred_language->langcode,
    '#options' => $language_options,
    '#description' => $mode ? 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;
}