gl_ws_send_translations.inc in GlobalLink Connect for Drupal 7.7
File
gl_ws/gl_ws_send_translations.inc
View source
<?php
require_once 'glc/GLExchange.php';
require_once 'glc/model/PDConfig.inc.php';
require_once 'glc/model/Submission.inc.php';
require_once 'glc/model/Document.inc.php';
function globallink_send_documents_for_translation_to_pd(&$globallink_arr, $pd_obj, $submission) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Connecting to PD - %pd', array(
'%pd' => print_r($submission, TRUE),
), WATCHDOG_DEBUG);
}
$connectorConfig = new PDConfig();
$connectorConfig->url = $pd_obj->url;
$connectorConfig->username = $pd_obj->username;
$connectorConfig->password = $pd_obj->password;
$connectorConfig->userAgent = $pd_obj->userAgent;
$glExchange = new GLExchange($connectorConfig);
$glExchange
->initSubmission($submission);
$client_identifier = rand() . $submission->project->shortcode . REQUEST_TIME;
foreach ($globallink_arr as $gl) {
foreach ($gl as $globallink) {
$document = new PDDocument();
$document->name = $globallink->sourceFileName;
$document->encoding = 'UTF-8';
$document->fileformat = $pd_obj->classifier;
$document->clientIdentifier = $client_identifier;
$document->sourceLanguage = str_replace('_', '-', $globallink->sourceLocale);
$document->targetLanguages = str_replace('_', '-', $globallink->targetLocale);
$document->data = $globallink->sourceXML;
$md_arr = array();
$md_arr['type'] = $globallink->metadata;
if ($globallink->metadata != GLOBALLINK_ENTITY_TYPE_NODE && $globallink->metadata != GLOBALLINK_ENTITY_TYPE_ENTITY) {
$md_arr['type_id'] = $globallink->otherObjectId;
}
else {
$md_arr['type_id'] = $globallink->nid;
}
$document->metadata = $md_arr;
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Doc - %pd', array(
'%pd' => print_r($document, TRUE),
), WATCHDOG_DEBUG);
}
$ticket = $glExchange
->uploadTranslatable($document);
$globallink->documentTicket = $ticket;
}
}
$submission_ticket = $glExchange
->startSubmission();
foreach ($globallink_arr as $gl) {
foreach ($gl as $globallink) {
$globallink->submissionTicket = $submission_ticket;
}
}
}