function locale_translation_batch_version_check

Same name and namespace in other branches
  1. 11.x core/modules/locale/locale.batch.inc \locale_translation_batch_version_check()

Implements callback_batch_operation().

Checks for changed project versions, and cleans-up data from the old version. For example when a module is updated. This will make the translation import system use translations that match the current version.

Parameters

string $project: Machine name of the project for which to check the translation status.

string $langcode: Language code of the language for which to check the translation.

array|\ArrayAccess $context: The batch context.

1 call to locale_translation_batch_version_check()
LocaleTranslationChangeProjectVersionTest::testUpdateImportSourceRemote in core/modules/locale/tests/src/Functional/LocaleTranslationChangeProjectVersionTest.php
Tests update translations when project version changes.
1 string reference to 'locale_translation_batch_version_check'
_locale_translation_batch_status_operations in core/modules/locale/locale.compare.inc
Constructs batch operations for checking remote translation status.

File

core/modules/locale/locale.batch.inc, line 40

Code

function locale_translation_batch_version_check(string $project, string $langcode, array|\ArrayAccess &$context) {
  $locale_project = \Drupal::service('locale.project')->get($project);
  if (empty($locale_project)) {
    return;
  }
  $status = \Drupal::keyValue('locale.translation_status')->get($project);
  if (!isset($status[$langcode])) {
    return;
  }
  if ($locale_project['version'] == $status[$langcode]->version) {
    return;
  }
  \Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
  locale_translation_status_delete_projects([
    $project,
  ]);
  locale_translate_delete_translation_files([
    $project,
  ]);
  $context['message'] = t('Checked version of %project.', [
    '%project' => $project,
  ]);
}

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