function locale_translate_batch_build

Same name in other branches
  1. 9 core/modules/locale/locale.bulk.inc \locale_translate_batch_build()
  2. 8.9.x core/modules/locale/locale.bulk.inc \locale_translate_batch_build()
  3. 10 core/modules/locale/locale.bulk.inc \locale_translate_batch_build()

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.

2 calls to locale_translate_batch_build()
ImportForm::submitForm in core/modules/locale/src/Form/ImportForm.php
Form submission handler.
locale_translate_batch_import_files in core/modules/locale/locale.bulk.inc
Prepare a batch to import all translations.

File

core/modules/locale/locale.bulk.inc, line 137

Code

function locale_translate_batch_build(array $files, array $options) {
    $options += [
        'overwrite_options' => [],
        'customized' => LOCALE_NOT_CUSTOMIZED,
        'finish_feedback' => TRUE,
    ];
    if (count($files)) {
        $batch_builder = (new BatchBuilder())->setFile(\Drupal::service('extension.list.module')->getPath('locale') . '/locale.bulk.inc')
            ->setTitle(t('Importing interface translations'))
            ->setErrorMessage(t('Error importing interface translations'));
        foreach ($files as $file) {
            // We call locale_translate_batch_import for every batch operation.
            $batch_builder->addOperation('locale_translate_batch_import', [
                $file,
                $options,
            ]);
        }
        // Save the translation status of all files.
        $batch_builder->addOperation('locale_translate_batch_import_save', []);
        // Add a final step to refresh JavaScript and configuration strings.
        $batch_builder->addOperation('locale_translate_batch_refresh', []);
        if ($options['finish_feedback']) {
            $batch_builder->setFinishCallback('locale_translate_batch_finished');
        }
        return $batch_builder->toArray();
    }
    return FALSE;
}

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