You are here

function locale_system_update in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/locale/locale.module \locale_system_update()
  2. 6 modules/locale/locale.module \locale_system_update()
  3. 7 modules/locale/locale.module \locale_system_update()
  4. 9 core/modules/locale/locale.module \locale_system_update()

Imports translations when new modules or themes are installed.

This function will start a batch to import translations for the added components.

Parameters

array $components: An array of arrays of component (theme and/or module) names to import translations for, indexed by type.

2 calls to locale_system_update()
locale_modules_installed in core/modules/locale/locale.module
Implements hook_modules_installed().
locale_themes_installed in core/modules/locale/locale.module
Implements hook_themes_installed().

File

core/modules/locale/locale.module, line 405
Enables the translation of the user interface to languages other than English.

Code

function locale_system_update(array $components) {
  $components += [
    'module' => [],
    'theme' => [],
  ];
  $list = array_merge($components['module'], $components['theme']);

  // Skip running the translation imports if in the installer,
  // because it would break out of the installer flow. We have
  // built-in support for translation imports in the installer.
  if (!InstallerKernel::installationAttempted() && locale_translatable_language_list()) {
    $module_handler = \Drupal::moduleHandler();
    if (\Drupal::config('locale.settings')
      ->get('translation.import_enabled')) {
      $module_handler
        ->loadInclude('locale', 'inc', 'locale.compare');

      // Update the list of translatable projects and start the import batch.
      // Only when new projects are added the update batch will be triggered.
      // Not each enabled module will introduce a new project. E.g. sub modules.
      $projects = array_keys(locale_translation_build_projects());
      if ($list = array_intersect($list, $projects)) {
        $module_handler
          ->loadInclude('locale', 'inc', 'locale.fetch');

        // Get translation status of the projects, download and update
        // translations.
        $options = _locale_translation_default_update_options();
        $batch = locale_translation_batch_update_build($list, [], $options);
        batch_set($batch);
      }
    }

    // Construct a batch to update configuration for all components. Installing
    // this component may have installed configuration from any number of other
    // components. Do this even if import is not enabled because parsing new
    // configuration may expose new source strings.
    $module_handler
      ->loadInclude('locale', 'inc', 'locale.bulk');
    if ($batch = locale_config_batch_update_components([])) {
      batch_set($batch);
    }
  }
}