You are here

function _l10n_update_fetch_operations in Localization update 7.2

Helper function to construct the batch operations to fetch translations.

Parameters

array $projects: Array of project names for which to check the state of translation files. Defaults to all translatable projects.

array $langcodes: Array of language codes. Defaults to all translatable languages.

array $options: Array of import options.

Return value

array Array of batch operations.

2 calls to _l10n_update_fetch_operations()
l10n_update_batch_fetch_build in ./l10n_update.fetch.inc
Builds a batch to download and import project translations.
l10n_update_batch_update_build in ./l10n_update.fetch.inc
Builds a batch to check, download and import project translations.

File

./l10n_update.fetch.inc, line 95
The API for download and import of translations.

Code

function _l10n_update_fetch_operations(array $projects, array $langcodes, array $options) {
  $operations = array();

  // If the process is going to download files from a remote, make sure the
  // files can be saved in the download directory.
  if (!empty($projects) && l10n_update_use_remote_source()) {
    $directory = variable_get('l10n_update_download_store', L10N_UPDATE_DEFAULT_TRANSLATION_PATH);

    // Do not download files if the directory is missing or can not be created.
    if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
      drupal_set_message(t('The directory %directory does not exist or is not writable.', array(
        '%directory' => $directory,
      )), 'error');
      watchdog('file system', 'The directory %directory does not exist or is not writable.', array(
        '%directory' => $directory,
      ), WATCHDOG_ERROR);
      return $operations;
    }
    l10n_update_ensure_htaccess();
  }
  foreach ($projects as $project) {
    foreach ($langcodes as $langcode) {
      if (l10n_update_use_remote_source()) {
        $operations[] = array(
          'l10n_update_batch_fetch_download',
          array(
            $project,
            $langcode,
          ),
        );
      }
      $operations[] = array(
        'l10n_update_batch_fetch_import',
        array(
          $project,
          $langcode,
          $options,
        ),
      );
    }
  }
  return $operations;
}