function LocaleImportBatch::buildBatch
Same name and namespace in other branches
- main core/modules/locale/src/LocaleImportBatch.php \Drupal\locale\LocaleImportBatch::buildBatch()
Build a locale batch from an array of files.
Parameters
array $files: Array of file objects to import.
array $options: An array with options that can have the following elements:
- 'langcode': The language code. Optional, defaults to NULL, which means that the language will be detected from the name of the files.
- 'overwrite_options': Overwrite options array as defined in Drupal\locale\PoDatabaseWriter. Optional, defaults to an empty array.
- 'customized': Flag indicating whether the strings imported from $file are customized translations or come from a community source. Use LOCALE_CUSTOMIZED or LOCALE_NOT_CUSTOMIZED. Optional, defaults to LOCALE_NOT_CUSTOMIZED.
- 'finish_feedback': Whether or not to give feedback to the user when the batch is finished. Optional, defaults to TRUE.
Return value
array|bool A batch structure or FALSE if $files was empty.
File
-
core/
modules/ locale/ src/ LocaleImportBatch.php, line 62
Class
- LocaleImportBatch
- Provides the locale import batch services.
Namespace
Drupal\localeCode
public function buildBatch(array $files, array $options) : array|bool {
$options += [
'overwrite_options' => [],
'customized' => LOCALE_NOT_CUSTOMIZED,
'finish_feedback' => TRUE,
];
if (count($files)) {
$batch_builder = (new BatchBuilder())->setTitle($this->t('Importing interface translations'))
->setErrorMessage($this->t('Error importing interface translations'));
foreach ($files as $file) {
// We call self::batchImport for every batch operation.
$batch_builder->addOperation(self::class . ':batchImport', [
$file,
$options,
]);
}
// Save the translation status of all files.
$batch_builder->addOperation(self::class . ':batchSave', []);
// Add a final step to refresh JavaScript and configuration strings.
$batch_builder->addOperation(self::class . ':batchRefresh', []);
if ($options['finish_feedback']) {
$batch_builder->setFinishCallback(self::class . ':batchFinished');
}
return $batch_builder->toArray();
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.