You are here

function locale_translation_batch_status_build in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/locale.compare.inc \locale_translation_batch_status_build()

Builds a batch to get the status of remote and local translation files.

The batch process fetches the state of both local and (if configured) remote translation files. The data of the most recent translation is stored per per project and per language. This data is stored in a state variable 'locale.translation_status'. The timestamp it was last updated is stored in the state variable 'locale.translation_last_checked'.

Parameters

array $projects: Array of project names for which to check the state of translation files. Defaults to all translatable projects.

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

Return value

array Batch definition array.

1 call to locale_translation_batch_status_build()
locale_translation_check_projects_batch in core/modules/locale/locale.compare.inc
Gets and stores the status and timestamp of remote po files.

File

core/modules/locale/locale.compare.inc, line 235
The API for comparing project translation status with available translation.

Code

function locale_translation_batch_status_build($projects = [], $langcodes = []) {
  $projects = $projects ? $projects : array_keys(locale_translation_get_projects());
  $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
  $options = _locale_translation_default_update_options();
  $operations = _locale_translation_batch_status_operations($projects, $langcodes, $options);
  $batch_builder = (new BatchBuilder())
    ->setFile(\Drupal::service('extension.list.module')
    ->getPath('locale') . '/locale.batch.inc')
    ->setTitle(t('Checking translations'))
    ->setErrorMessage(t('Error checking translation updates.'))
    ->setFinishCallback('locale_translation_batch_status_finished');
  array_walk($operations, function ($operation) use ($batch_builder) {
    call_user_func_array([
      $batch_builder,
      'addOperation',
    ], $operation);
  });
  return $batch_builder
    ->toArray();
}