You are here

function lingotek_add_target_locales in Lingotek Translation 7.7

1 string reference to 'lingotek_add_target_locales'
lingotek_batch_update_entity_languages_by_profile in ./lingotek.batch.inc

File

./lingotek.batch.inc, line 871
Central location for batch create functions, before control is handed off to individual batch command files.

Code

function lingotek_add_target_locales($entity_params, $locales, LingotekProfile $profile, &$context) {
  $document_id = $entity_params['document_id'];
  $entity_type = $entity_params['type'];
  $entity_id = $entity_params['id'];
  if (empty($context['results'])) {
    $context['results'] = array();
  }
  if (empty($context['results']['added'])) {

    // initialize the counter of removed targets.
    $context['results']['added'] = 0;
  }
  $api = LingotekApi::instance();
  $document = $api
    ->getDocument($document_id);
  foreach ($locales as $l) {

    // Don't add the target if it's the same as the source.
    if ($document->sourceLanguage == $l) {
      continue;
    }
    $workflow_id = $profile
      ->getWorkflow($l);
    $result = $api
      ->addTranslationTarget($document_id, NULL, $l, $workflow_id);
    if ($result) {
      LingotekSync::setTargetStatus($entity_type, $entity_id, $l, LingotekSync::STATUS_PENDING);
      $context['results']['added']++;
    }
  }
}