You are here

function locale_translation_batch_fetch_download in Drupal 9

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

Implements callback_batch_operation().

Downloads a remote gettext file into the translations directory. When successfully the translation status is updated.

Parameters

object $project: Source object of the translatable project.

string $langcode: Language code.

array $context: The batch context.

See also

locale_translation_batch_fetch_import()

2 string references to 'locale_translation_batch_fetch_download'
install_import_translations in core/includes/install.core.inc
Imports languages via a batch process during installation.
_locale_translation_fetch_operations in core/modules/locale/locale.fetch.inc
Helper function to construct the batch operations to fetch translations.

File

core/modules/locale/locale.batch.inc, line 144
Batch process to check the availability of remote or local po files.

Code

function locale_translation_batch_fetch_download($project, $langcode, &$context) {
  $sources = locale_translation_get_status([
    $project,
  ], [
    $langcode,
  ]);
  if (isset($sources[$project][$langcode])) {
    $source = $sources[$project][$langcode];
    if (isset($source->type) && $source->type == LOCALE_TRANSLATION_REMOTE) {
      if ($file = locale_translation_download_source($source->files[LOCALE_TRANSLATION_REMOTE], 'translations://')) {
        $context['message'] = t('Downloaded %langcode translation for %project.', [
          '%langcode' => $langcode,
          '%project' => $source->project,
        ]);
        locale_translation_status_save($source->name, $source->langcode, LOCALE_TRANSLATION_LOCAL, $file);
      }
      else {
        $context['results']['failed_files'][] = $source->files[LOCALE_TRANSLATION_REMOTE];
      }
    }
  }
}