You are here

function lingotek_grid_download_selected in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lingotek.bulk_grid.inc \lingotek_grid_download_selected()
  2. 7.6 lingotek.bulk_grid.inc \lingotek_grid_download_selected()
1 call to lingotek_grid_download_selected()
lingotek_grid_action_submit in ./lingotek.bulk_grid.inc
Submit function for The Grid's actions The action corresponds to the key of the option selected Often redirects to batch operations or to other pages entirely

File

./lingotek.bulk_grid.inc, line 1230

Code

function lingotek_grid_download_selected($entity_type, $entity_ids, $target_locales) {
  $operations = array();
  $entities = entity_load($entity_type, $entity_ids);
  $all_target_locales = $target_locales;
  foreach ($entities as $entity) {
    $update_context = [
      'entity' => $entity,
      'entity_type' => $entity_type,
    ];
    $operations[] = array(
      'lingotek_get_and_update_target_progress',
      array(
        $update_context,
      ),
    );
    $target_locales = $all_target_locales;

    // must reset $target_locales to the original array or else some target languages may be skipped during download
    if (variable_get('lingotek_enable_language_specific_profiles')) {

      // Filter out the target languages that should not be included for this entity.
      $profile = LingotekProfile::loadByEntity($entity_type, $entity);
      $target_locales = array_keys($profile
        ->filterTargetLocales($target_locales));
    }
    foreach ($target_locales as $locale) {

      // Skip language neutral taxonomy terms because their source is really English.
      if ($entity_type == 'taxonomy_term' && $entity->language == LANGUAGE_NONE && $locale == 'en_US') {
        continue;
      }
      $operations[] = array(
        'lingotek_entity_download',
        array(
          $entity,
          $entity_type,
          $locale,
        ),
      );
    }
  }
  $redirect = 'admin/settings/lingotek/manage/' . $entity_type;
  $batch = array(
    'title' => t('Downloading Translations'),
    'finished' => 'lingotek_sync_download_target_finished',
  );
  $batch['operations'] = $operations;
  batch_set($batch);
  batch_process($redirect);
}