function install_select_language

Selects which language to use during installation.

Parameters

$install_state: An array of information about the current installation state. The chosen langcode will be added here, if it was not already selected previously, as will a list of all available languages.

Return value

For interactive installations, a form or other page output allowing the language to be selected or providing information about language selection, if a language has not been chosen. Otherwise, an exception is thrown if a language cannot be chosen automatically.

File

drupal/core/includes/install.core.inc, line 1438
API functions for installing Drupal.

Code

function install_select_language(&$install_state) {

  // Find all available translation files.
  $files = install_find_translations();
  $install_state['translations'] += $files;

  // If a valid language code is set, continue with the next installation step.
  // When translations from the localization server are used, any language code
  // is accepted because the standard language list is kept in sync with the
  // langauges available at http://localize.drupal.org.
  // When files from the translation directory are used, we only accept
  // languages for which a file is available.
  if (!empty($_POST['langcode'])) {
    $standard_languages = LanguageManager::getStandardLanguageList();
    $langcode = $_POST['langcode'];
    if ($langcode == 'en' || isset($files[$langcode]) || isset($standard_languages[$langcode])) {
      $install_state['parameters']['langcode'] = $langcode;
      return;
    }
  }
  if (empty($install_state['parameters']['langcode'])) {

    // If we are performing an interactive installation, we display a form to
    // select a right language. If no translation files were found in the
    // translations directory, the form shows a list of standard languages. If
    // translation files were found the form shows a select list of the
    // corresponding languages to choose from.
    if ($install_state['interactive']) {
      drupal_set_title(st('Choose language'));
      include_once __DIR__ . '/form.inc';
      $elements = drupal_get_form('install_select_language_form', count($files) > 1 ? $files : array());
      return drupal_render($elements);
    }
    else {
      if (count($files) == 1) {
        $install_state['parameters']['langcode'] = current(array_keys($files));
        return;
      }
      else {
        throw new Exception(st('Sorry, you must select a language to continue the installation.'));
      }
    }
  }
}