You are here

function lingotek_config_download_selected in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.config.inc \lingotek_config_download_selected()
2 calls to lingotek_config_download_selected()
lingotek_config_action_submit in ./lingotek.config.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
lingotek_grid_download_ready in ./lingotek.bulk_grid.inc

File

./lingotek.config.inc, line 376
Config grid form elements

Code

function lingotek_config_download_selected($action, $lids) {
  $set_ids = array_unique(LingotekSync::getSetIdsFromLids($lids));
  if (empty($set_ids)) {
    drupal_set_message(t('No translations to download at this time. Make sure configuration items have been uploaded to Lingotek before trying to get translations for them.'), 'status', FALSE);
    drupal_goto('admin/settings/lingotek/manage/config');
  }
  $document_ids = LingotekSync::getConfigDocIdsFromSetIds($set_ids);
  $available_targets = Lingotek::getLanguages();
  unset($available_targets['en_US']);

  // all locales_source is assumed by i18n modules to be English
  list($verb, $target_locale) = explode('_', $action, 2);
  if ($verb != 'download') {
    throw LingotekException("Config download verb mismatch: expected 'download', received '{$verb}'");
  }
  if ($target_locale != 'all' && empty($available_targets[$target_locale])) {
    throw LingotekException("Config download received unknown target: {$target_locale}");
  }
  $download_targets = array();
  foreach ($document_ids as $doc_id) {
    if ($target_locale == 'all') {
      foreach (array_keys($available_targets) as $locale) {
        $target = new stdClass();
        $target->document_id = $doc_id;
        $target->locale = $locale;
        $download_targets[] = $target;
      }
    }
    else {
      $target = new stdClass();
      $target->document_id = $doc_id;
      $target->locale = $target_locale;
      $download_targets[] = $target;
    }
  }
  $redirect = 'admin/settings/lingotek/manage/config';
  $operations = lingotek_get_sync_download_batch_elements($download_targets, LingotekSync::STATUS_PENDING);
  $batch = array(
    'title' => t('Syncing Content and Translations'),
    'operations' => $operations,
    'file' => 'lingotek.batch.inc',
    'finished' => 'lingotek_sync_batch_finished',
  );
  batch_set($batch);
  batch_process($redirect);
}