function install_download_additional_translations_operations

Same name in other branches
  1. 9 core/includes/install.core.inc \install_download_additional_translations_operations()
  2. 8.9.x core/includes/install.core.inc \install_download_additional_translations_operations()
  3. 11.x core/includes/install.core.inc \install_download_additional_translations_operations()

Prepares the system for import and downloads additional translations.

Parameters

$install_state: An array of information about the current installation state.

Return value

array The batch definition, if there are language files to download.

1 call to install_download_additional_translations_operations()
install_import_translations in core/includes/install.core.inc
Imports languages via a batch process during installation.

File

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

Code

function install_download_additional_translations_operations(&$install_state) {
    \Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
    $langcode = $install_state['parameters']['langcode'];
    if (!($language = ConfigurableLanguage::load($langcode))) {
        // Create the language if not already shipped with a profile.
        $language = ConfigurableLanguage::createFromLangcode($langcode);
    }
    $language->save();
    // If a non-English language was selected, change the default language and
    // remove English.
    if ($langcode != 'en') {
        \Drupal::configFactory()->getEditable('system.site')
            ->set('langcode', $langcode)
            ->set('default_langcode', $langcode)
            ->save();
        \Drupal::service('language.default')->set($language);
        if (empty($install_state['profile_info']['keep_english'])) {
            if ($lang = ConfigurableLanguage::load('en')) {
                $lang->delete();
            }
        }
    }
    // If there is more than one language or the single one is not English, we
    // should download/import translations.
    $languages = \Drupal::languageManager()->getLanguages();
    $operations = [];
    foreach ($languages as $langcode => $language) {
        // The installer language was already downloaded. Available translations are
        // stored in $install_state. Check downloads for the other languages if any.
        // Ignore any download errors here, since we are in the middle of an install
        // process and there is no way back. We will not import what we cannot
        // download.
        if (!isset($install_state['translations'][$langcode])) {
            $operations[] = [
                'install_check_translations',
                [
                    $langcode,
                    $install_state['server_pattern'],
                ],
            ];
        }
    }
    return $operations;
}

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