function LocaleFetch::batchDownload
Same name and namespace in other branches
- 11.x core/modules/locale/src/LocaleFetch.php \Drupal\locale\LocaleFetch::batchDownload()
Implements callback_batch_operation().
Downloads a remote gettext file into the translations directory. When successfully the translation status is updated.
Parameters
string $project: The name of the project to import translations.
string $langcode: Language code.
array|\ArrayAccess $context: The batch context.
See also
\Drupal\locale\LocaleFetch::batchImport()
File
-
core/
modules/ locale/ src/ LocaleFetch.php, line 168
Class
- LocaleFetch
- Provides the locale fetch services.
Namespace
Drupal\localeCode
public function batchDownload(string $project, string $langcode, array|\ArrayAccess &$context) : void {
$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 = $this->localeFileManager
->downloadTranslationSource($source->files[LOCALE_TRANSLATION_REMOTE], 'translations://')) {
$context['message'] = $this->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];
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.