function lingotek_sync_target_locales in Lingotek Translation 7.7
1 call to lingotek_sync_target_locales()
File
- ./
lingotek.module, line 1195
Code
function lingotek_sync_target_locales($entity, $entity_type) {
$ln = LingotekEntity::load($entity, $entity_type);
$api = LingotekApi::instance();
$document_id = $ln
->lingotekDocumentId();
if (empty($document_id)) {
$document_id = LingotekSync::getDocIdFromEntityId($entity_type, $entity->nid);
$entity->lingotek['document_id'] = $document_id;
}
$source = isset($ln->language) ? $ln->language : language_default()->language;
$source = Lingotek::convertDrupal2Lingotek($source);
$target_locales = Lingotek::getLanguagesWithoutSource($source);
$profile = LingotekProfile::loadById($ln
->getMetadataValue('profile'));
$target_locales = $profile
->filterTargetLocales(array_keys($target_locales));
$target_translations = (array) $api
->listTranslationTargets($document_id);
$drupal_target_locales = $target_locales;
$tms_target_locales = array();
foreach ($target_translations['translationTargets'] as $target_object) {
$item = (array) $target_object;
$tms_target_locales[$item['language']] = 1;
}
foreach ($drupal_target_locales as $dtl => $val1) {
if (LingotekSync::getTargetStatus($document_id, $dtl) == LingotekSync::STATUS_UNTRACKED) {
LingotekSync::setTargetStatus($ln
->getEntityType(), $ln
->getId(), $dtl, LingotekSync::STATUS_NONE);
}
foreach ($tms_target_locales as $ttl => $val2) {
if ($dtl == $ttl) {
unset($drupal_target_locales[$dtl]);
unset($tms_target_locales[$dtl]);
}
}
}
foreach ($drupal_target_locales as $dtl => $val) {
$workflow = isset($val['workflow_id']) ? $val['workflow_id'] : '';
$api
->addTranslationTarget($document_id, NULL, $dtl, $workflow);
}
foreach ($tms_target_locales as $ttl => $val) {
LingotekSync::setTargetStatus($ln
->getEntityType(), $ln
->getId(), $ttl, LingotekSync::STATUS_UNTRACKED);
}
$update_context = [
'entity' => $entity,
'entity_type' => $entity_type,
];
lingotek_get_and_update_target_progress($update_context);
}