View source
<?php
$GLOBALS['_lingotek_client'] = new LingotekSession();
function lingotek_can_log_in() {
global $_lingotek_client;
if ($_lingotek_client
->canLogIn()) {
return t("True");
}
else {
return t("False");
}
}
function lingotek_download_document($source_node, $target_node, $save = TRUE) {
global $_lingotek_client, $_lingotek_locale;
$document_id = lingotek_lingonode($source_node->nid, 'document_id');
$target_language = $_lingotek_locale[$target_node->language];
$params = array(
'documentId' => $document_id,
'targetLanguage' => $target_language,
'useSource' => 'TRUE',
);
if (!isset($target_language) || !isset($document_id)) {
lingotek_error('downloadDocument was not called because it was missing parameters', $params);
return;
}
$text = $_lingotek_client
->download("downloadDocument", $params);
try {
$xml = new SimpleXMLElement($text);
} catch (Exception $e) {
lingotek_error("downloadDocument FAILED", array(
'xml' => $text,
'error' => $e
->getMessage(),
));
}
$titles = $xml
->xpath("title");
$bodies = $xml
->xpath("body");
$target_node->title = decode_entities(lingotek_xml_decode($titles[0]));
$target_node->body = lingotek_xml_decode($bodies[0]);
$target_node->teaser = node_teaser($target_node->body, $source_node->format);
$target_node->status = $source_node->status;
$target_node->promote = $source_node->promote;
$target_node->sticky = $source_node->sticky;
$target_node->tnid = $source_node->nid;
if ($save) {
if (!isset($target_node->vid)) {
$target_node->vid = $target_node->nid;
}
node_save($target_node);
}
}
function lingotek_save_segment($source_text, $target_text, $target_language, $doc_id) {
global $_lingotek_client;
$param = array(
"sourceText" => $source_text,
"targetText" => $target_text,
"targetLanguage" => $target_language,
"documentId" => $doc_id,
"overwrite" => 0,
);
$save_segment = $_lingotek_client
->request("saveSegment", $param);
return $save_segment->results == "success";
}
function lingotek_add_project($name) {
global $_lingotek_client;
$output = $_lingotek_client
->request('addProject', array(
'projectName' => $name,
));
if ($output->results == "success") {
variable_set('lingotek_project', $output->id);
return $output->id;
}
}
function lingotek_add_vault($name) {
global $_lingotek_client;
$output = $_lingotek_client
->request('addTMVault', array(
'tmVaultName' => $name,
));
if ($output->results == "success") {
variable_set('lingotek_vault', $output->id);
return $output->id;
}
}
function lingotek_add_vault_to_project() {
global $_lingotek_client;
$vault_id = variable_get('lingotek_vault', '');
$project_id = variable_get('lingotek_project', '');
if ($vault_id != '' && $project_id != '') {
$param = array(
'project_id' => $project_id,
'index_id' => $vault_id,
);
$_lingotek_client
->request('addProjectTMVault', $param);
}
}
function lingotek_tnid($node) {
$tnid = lingotek_lingonode($node->nid, 'tnid');
if ($tnid) {
return $tnid;
}
else {
return $node->tnid;
}
}
function lingotek_node_get_translations($tnid) {
static $translations = array();
if (is_numeric($tnid) && $tnid) {
if (!isset($translations[$tnid])) {
$translations[$tnid] = array();
$query = 'SELECT n.nid, n.title, n.language FROM {node} n LEFT JOIN lingotek ln ON n.nid = ln.nid AND ln.{lingokey} = \'tnid\' WHERE n.tnid = %d OR ln.lingovalue = \'%d\'';
$result = db_query($query, $tnid, $tnid);
while ($node = db_fetch_object($result)) {
$translations[$tnid][$node->language] = $node;
}
}
$source = node_load(array(
'nid' => $tnid,
));
unset($translations[$tnid][$source->language]);
return $translations[$tnid];
}
}
function lingotek_get_cms_key() {
global $_lingotek_client;
$output = $_lingotek_client
->request("getCMSKey");
if ($output->results == "success") {
variable_del('lingotek_password');
return $output->cms;
}
else {
return "";
}
}
function lingotek_get_communities() {
global $_lingotek_client;
$options = array();
if (!$_lingotek_client
->canLogIn()) {
return $options;
}
$list_communities = $_lingotek_client
->request("listCommunities", array());
if ($list_communities->results == "success") {
foreach ($list_communities->communities as $community) {
$options[$community->id] = t($community->name);
}
}
return $options;
}
function lingotek_get_machine_translation_engines() {
$engines = array();
$engines['google'] = t("Google MT");
$engines['microsoft'] = t("Microsoft MT");
return $engines;
}
function lingotek_get_node($lang_prefix, $tnid) {
$result = db_query("SELECT n.nid FROM {node} n INNER JOIN {lingotek} ln ON n.nid = ln.nid AND ln.lingokey = 'tnid' WHERE n.language = '%s' AND ln.lingovalue = '%s'", $lang_prefix, $tnid);
$row = db_fetch_object($result);
if ($row) {
return node_load(array(
'nid' => $row->nid,
));
}
else {
return node_load(array(
'language' => $lang_prefix,
'tnid' => $tnid,
));
}
}
function lingotek_get_phase_templates() {
global $_lingotek_client;
$options = array();
$options[1] = t("Translation Only");
$options[2] = t("Translation + 1 review");
$options[3] = t("Translation + 2 reviews");
$options[4] = t("Translation + 3 reviews");
if (!$_lingotek_client
->canLogIn()) {
return $options;
}
$list_phase_templates = $_lingotek_client
->request("listPhaseTemplates");
if ($list_phase_templates->results == "success") {
foreach ($list_phase_templates->phaseTemplates as $phase_template) {
$options[$phase_template->id] = t($phase_template->name);
}
}
return $options;
}
function lingotek_get_projects() {
global $_lingotek_client;
$options = array();
if (!$_lingotek_client
->canLogIn()) {
return $options;
}
$list_projects = $_lingotek_client
->request("listProjects");
if ($list_projects->results == "success") {
foreach ($list_projects->projects as $project) {
$options[$project->id] = t($project->name);
}
}
return $options;
}
function lingotek_get_sync_methods() {
$methods = array();
$methods[0] = t("Never");
$methods[1] = t("Always");
$methods[100] = t("100%");
return $methods;
}
function lingotek_get_vaults() {
global $_lingotek_client;
$options = array();
if (!$_lingotek_client
->isLoggedIn()) {
return $options;
}
$list_TM_vaults = $_lingotek_client
->request("listTMVaults");
if ($list_TM_vaults->results == "success") {
foreach ($list_TM_vaults->personalVaults as $vault) {
$options["Personal Vaults"][$vault->id] = t($vault->name);
}
foreach ($list_TM_vaults->publicVaults as $vault) {
$options["Public Vaults"][$vault->id] = t($vault->name);
}
}
return $options;
}
function lingotek_workbench_phase_link($document_id, $phase_id, $label) {
global $user;
$arr = array(
'community' => variable_get('lingotek_community', ''),
'id' => $user->name,
'time' => time(),
'document' => $document_id,
'phase' => $phase_id,
);
$mode = 'cmsWorkbench.action';
$json_str = json_encode($arr);
$path = variable_get('lingotek_url', '') . "/lingopoint/portal/" . $mode . "?auth_json=" . urlencode($json_str) . "&hmac=" . urlencode(LingotekSession::create_mac($json_str));
if (module_exists('lightbox2') && variable_get('lingotek_use_lightbox', FALSE)) {
return l(t($label), $path, array(
'attributes' => array(
'rel' => 'lightframe',
),
));
}
else {
return l(t($label), '#', array(
'attributes' => array(
'onclick' => 'window.open(\'' . $path . '\'); return false;',
),
));
}
}
function lingotek_get_xliff($doc_id) {
global $_lingotek_client;
$xliff_text = "";
$params = array(
'documentId' => $doc_id,
);
return $_lingotek_client
->download("downloadDocumentAsXliff", $params);
}