You are here

function install_download_additional_translations_operations in Drupal 9

Same name and namespace in other branches
  1. 8 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

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 1673
API functions for installing Drupal.

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;
}