You are here

function lingotek_add_language_specific_targets in Lingotek Translation 7.7

Adds a languages specific target to the TMS

1 string reference to 'lingotek_add_language_specific_targets'
lingotek_get_add_language_specific_operations in ./lingotek.batch.inc
Get the operations for the "Add language-specific translations" bulk action

File

./lingotek.util.inc, line 3358
Utility functions.

Code

function lingotek_add_language_specific_targets($entity_type, $entity_id, $context) {
  $api = LingotekApi::instance();
  $entity = lingotek_entity_load_single($entity_type, $entity_id);
  $document_id = isset($entity->lingotek['document_id']) ? $entity->lingotek['document_id'] : FALSE;
  if (!$document_id) {
    return;
  }
  $profile = LingotekProfile::loadById($entity->lingotek['profile']);
  $target_locales = $profile
    ->getAllTargetLocaleOverrides();
  foreach ($target_locales as $target_locale => $settings) {
    $error_target_status = lingotek_keystore($entity_type, $entity_id, 'target_sync_status_' . $target_locale);
    if ($error_target_status !== LingotekSync::STATUS_ERROR) {
      continue;
    }
    $language_specific_workflow = isset($settings['workflow_id']) ? $settings['workflow_id'] : FALSE;
    if ($language_specific_workflow) {
      $result = $api
        ->addTranslationTarget($document_id, NULL, $target_locale, $language_specific_workflow);
      if ($result) {
        lingotek_keystore($entity_type, $entity_id, 'target_sync_status_' . $target_locale, LingotekSync::STATUS_PENDING);
        if (empty($context['results'])) {
          $context['results']['language_specific_targets'] = 1;
        }
        else {
          $context['results']['language_specific_targets'] += 1;
        }
      }
      else {
        if (empty($context['results'])) {
          $context['results']['language_specific_target_errors'] = 1;
        }
        else {
          $context['results']['language_specific_target_errors'] += 1;
        }
      }
    }
  }
}