function locale_translation_batch_status_check

Same name in other branches
  1. 9 core/modules/locale/locale.batch.inc \locale_translation_batch_status_check()
  2. 8.9.x core/modules/locale/locale.batch.inc \locale_translation_batch_status_check()
  3. 11.x core/modules/locale/locale.batch.inc \locale_translation_batch_status_check()

Implements callback_batch_operation().

Checks the presence and creation time po translation files in located at remote server location and local file system.

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 $options: An array with options that can have the following elements:

  • 'finish_feedback': Whether or not to give feedback to the user when the batch is finished. Optional, defaults to TRUE.
  • 'use_remote': Whether or not to check the remote translation file. Optional, defaults to TRUE.

array|\ArrayAccess $context: The batch context.

1 call to locale_translation_batch_status_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_status_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 82

Code

function locale_translation_batch_status_check($project, $langcode, array $options, &$context) {
    $failure = $checked = FALSE;
    $options += [
        'finish_feedback' => TRUE,
        'use_remote' => TRUE,
    ];
    $source = locale_translation_get_status([
        $project,
    ], [
        $langcode,
    ]);
    $source = $source[$project][$langcode];
    // Check the status of local translation files.
    if (isset($source->files[LOCALE_TRANSLATION_LOCAL])) {
        if ($file = locale_translation_source_check_file($source)) {
            locale_translation_status_save($source->name, $source->langcode, LOCALE_TRANSLATION_LOCAL, $file);
        }
        $checked = TRUE;
    }
    // Check the status of remote translation files.
    if ($options['use_remote'] && isset($source->files[LOCALE_TRANSLATION_REMOTE])) {
        $remote_file = $source->files[LOCALE_TRANSLATION_REMOTE];
        if ($result = locale_translation_http_check($remote_file->uri)) {
            // Update the file object with the result data. In case of a redirect we
            // store the resulting uri.
            if (isset($result['last_modified'])) {
                $remote_file->uri = $result['location'] ?? $remote_file->uri;
                $remote_file->timestamp = $result['last_modified'];
                locale_translation_status_save($source->name, $source->langcode, LOCALE_TRANSLATION_REMOTE, $remote_file);
            }
            // @todo What to do with when the file is not found (404)? To prevent
            //   re-checking within the TTL (1day, 1week) we can set a last_checked
            //   timestamp or cache the result.
            $checked = TRUE;
        }
        else {
            $failure = TRUE;
        }
    }
    // Provide user feedback and record success or failure for reporting at the
    // end of the batch.
    if ($options['finish_feedback'] && $checked) {
        $context['results']['files'][] = $source->name;
    }
    if ($failure && !$checked) {
        $context['results']['failed_files'][] = $source->name;
    }
    $context['message'] = t('Checked %langcode translation for %project.', [
        '%langcode' => $langcode,
        '%project' => $source->project,
    ]);
}

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