You are here

function l10n_update_batch_build in Localization update 7.2

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 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 L10N_UPDATE_CUSTOMIZED or L10N_UPDATE_NOT_CUSTOMIZED. Optional, defaults to L10N_UPDATE_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 l10n_update_batch_build()
l10n_update_batch_import_files in ./l10n_update.bulk.inc
Prepare a batch to import all translations.
l10n_update_import_form_submit in ./l10n_update.bulk.inc
Form submission handler for l10n_update_import_form().

File

./l10n_update.bulk.inc, line 387
Mass import-export and batch import functionality for Gettext .po files.

Code

function l10n_update_batch_build(array $files, array $options) {
  $options += array(
    'overwrite_options' => array(),
    'customized' => L10N_UPDATE_NOT_CUSTOMIZED,
    'finish_feedback' => TRUE,
  );
  if (count($files)) {
    $operations = array();
    foreach ($files as $file) {

      // We call l10n_update_batch_import for every batch operation.
      $operations[] = array(
        'l10n_update_batch_import',
        array(
          $file,
          $options,
        ),
      );
    }

    // Save the translation status of all files.
    $operations[] = array(
      'l10n_update_batch_import_save',
      array(),
    );

    // Add a final step to refresh JavaScript and configuration strings.
    $operations[] = array(
      'l10n_update_batch_refresh',
      array(),
    );
    $batch = array(
      'operations' => $operations,
      'title' => t('Importing interface translations'),
      'progress_message' => '',
      'error_message' => t('Error importing interface translations'),
      'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
    );
    if ($options['finish_feedback']) {
      $batch['finished'] = 'l10n_update_batch_finished';
    }
    return $batch;
  }
  return FALSE;
}