function install_select_language

Same name and namespace in other branches
  1. 9 core/includes/install.core.inc \install_select_language()
  2. 8.9.x core/includes/install.core.inc \install_select_language()
  3. 10 core/includes/install.core.inc \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

array|null 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

core/includes/install.core.inc, line 1358

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
    // languages 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($install_state['parameters']['langcode'])) {
        $standard_languages = LanguageManager::getStandardLanguageList();
        $langcode = $install_state['parameters']['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']) {
            return install_get_form('Drupal\\Core\\Installer\\Form\\SelectLanguageForm', $install_state);
        }
        else {
            if (count($files) == 1) {
                $install_state['parameters']['langcode'] = current(array_keys($files));
                return;
            }
            else {
                throw new InstallerException('You must select a language to continue the installation.');
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.