function locale_translation_batch_status_build

Same name and namespace in other branches
  1. 10 core/modules/locale/locale.compare.inc \locale_translation_batch_status_build()
  2. 11.x core/modules/locale/locale.compare.inc \locale_translation_batch_status_build()
  3. 9 core/modules/locale/locale.compare.inc \locale_translation_batch_status_build()
  4. 8.9.x 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.

Deprecated

in drupal:11.4.0 and is removed from drupal:13.0.0. Use \Drupal::service(LocaleProjectChecker::class)->triggerBatch() instead, this now calls batch_set immediately instead of returning the array.

See also

https://www.drupal.org/node/3589759

File

core/modules/locale/locale.compare.inc, line 229

Code

function locale_translation_batch_status_build($projects = [], $langcodes = []) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use \\Drupal::service(LocaleProjectChecker::class)->triggerBatch() instead, this now calls batch_set immediately instead of returning the array. See https://www.drupal.org/node/3589759', E_USER_DEPRECATED);
  $projects = $projects ?: array_keys(\Drupal::service(LocaleProjectRepository::class)->getAll());
  $langcodes = $langcodes ?: array_keys(locale_translatable_language_list());
  $options = LocaleDefaultOptions::updateOptions();
  $operations = \Drupal::service(LocaleFetch::class)->getStatusOperations($projects, $langcodes, $options);
  $batch_builder = (new BatchBuilder())->setTitle(t('Checking translations'))
    ->setErrorMessage(t('Error checking translation updates.'))
    ->setFinishCallback(LocaleProjectChecker::class . ':batchFinished');
  array_walk($operations, function ($operation) use ($batch_builder) {
    call_user_func_array([
      $batch_builder,
      'addOperation',
    ], $operation);
  });
  return $batch_builder->toArray();
}

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