You are here

function locale_translation_batch_update_build in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/locale/locale.fetch.inc \locale_translation_batch_update_build()
  2. 9 core/modules/locale/locale.fetch.inc \locale_translation_batch_update_build()

Builds a batch to check, download and import project translations.

Parameters

array $projects: Array of project names for which to update the translations. Defaults to all translatable projects.

array $langcodes: Array of language codes. Defaults to all translatable languages.

array $options: Array of import options. See locale_translate_batch_import_files().

Return value

array Batch definition array.

5 calls to locale_translation_batch_update_build()
install_finish_translations in core/includes/install.core.inc
Finishes importing files at end of installation.
locale_cron_fill_queue in core/modules/locale/locale.translation.inc
Populate a queue with project to check for translation updates.
locale_form_language_admin_add_form_alter_submit in core/modules/locale/locale.module
Form submission handler for language_admin_add_form().
locale_system_update in core/modules/locale/locale.module
Imports translations when new modules or themes are installed.
TranslationStatusForm::submitForm in core/modules/locale/src/Form/TranslationStatusForm.php
Form submission handler.

File

core/modules/locale/locale.fetch.inc, line 31
The API for download and import of translations from remote and local sources.

Code

function locale_translation_batch_update_build($projects = [], $langcodes = [], $options = []) {
  \Drupal::moduleHandler()
    ->loadInclude('locale', 'inc', 'locale.compare');
  $projects = $projects ? $projects : array_keys(locale_translation_get_projects());
  $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
  $status_options = $options;
  $status_options['finish_feedback'] = FALSE;
  $batch_builder = (new BatchBuilder())
    ->setFile(\Drupal::service('extension.list.module')
    ->getPath('locale') . '/locale.batch.inc')
    ->setTitle(t('Updating translations'))
    ->setErrorMessage(t('Error importing translation files'))
    ->setFinishCallback('locale_translation_batch_fetch_finished');

  // Check status of local and remote translation files.
  $operations = _locale_translation_batch_status_operations($projects, $langcodes, $status_options);

  // Download and import translations.
  $operations = array_merge($operations, _locale_translation_fetch_operations($projects, $langcodes, $options));
  array_walk($operations, function ($operation) use ($batch_builder) {
    call_user_func_array([
      $batch_builder,
      'addOperation',
    ], $operation);
  });
  return $batch_builder
    ->toArray();
}