function lingotek_node_view in Lingotek Translation 6
Same name and namespace in other branches
- 7.7 lingotek.module \lingotek_node_view()
- 7.2 lingotek.module \lingotek_node_view()
- 7.3 lingotek.module \lingotek_node_view()
- 7.4 lingotek.module \lingotek_node_view()
- 7.5 lingotek.module \lingotek_node_view()
- 7.6 lingotek.module \lingotek_node_view()
1 call to lingotek_node_view()
File
- ./
lingotek.module, line 169
Code
function lingotek_node_view($node, $view_mode) {
global $_lingotek_client, $_lingotek_locale;
//Make sure we are looking at targets relative to the source language.
$source = $node;
if ($node->tnid) {
$source = node_load(array(
'nid' => $node->tnid,
));
}
//If the source Node has been deleted, prevent further community translation:
if ($source) {
if (!lingotek_lingonode($source->nid, 'document_id')) {
if ($_lingotek_client
->canLogIn()) {
//Update the node's information with what Lingotek has on it's translation progress.
lingotek_update_nodes($source);
$translations = lingotek_node_get_translations($node->tnid);
foreach ($translations as $target) {
lingotek_download_document($node, $target);
node_save($target);
}
}
}
}
if ($node->tnid && $node->tnid != $node->nid && $view_mode == 'full') {
if (lingotek_do_cache() && ($cache = cache_get('lingotek_' + $node->nid + '_link')) && !empty($cache->data) && time() < $cache->expire) {
$link = $cache->data;
}
else {
$doc_id = lingotek_lingonode($node->tnid, 'document_id');
$output = $_lingotek_client
->request('listTranslationTargets', array(
'documentId' => $doc_id,
));
if ($output->results == "success") {
$this_target;
$phase_id;
foreach ($output->translationTargets as $target) {
if ($target->language == $_lingotek_locale[$node->language]) {
$this_target = $target;
break;
}
}
$which_phase = 0;
//Must be returned in order:
foreach ($this_target->phases as $phase) {
if ($phase->percentComplete < 100) {
$phase_id = $phase->id;
break;
}
$which_phase++;
}
//Should we download at this point automatically at 100%?:
//TODO: This is delayed until a second refresh. Once to download, once to display changes...
if ($which_phase == count($this_target->phases)) {
if (!lingotek_lingonode($node->nid, "downloaded")) {
$source_node = node_load(array(
'nid' => $node->tnid,
));
lingotek_download_document($source_node, $node, TRUE);
lingotek_lingonode($node->nid, "downloaded", TRUE);
}
}
else {
//We only want to give this message until they reach 100%:
$message .= t('The translation of %title is still being worked on.', array(
'%title' => $node->title,
)) . " ";
$message .= lingotek_workbench_phase_link($doc_id, $phase_id, t("Help make it better.")) . " ";
if (user_access('view content progress tab')) {
$message .= '<span style="font-size: 80%">[' . l(t('progress'), 'node/' . $node->nid . '/lingotek_pm', array(
'html' => true,
)) . ']</span>';
}
}
}
$link = array(
'which_phase' => $which_phase,
'message' => $message,
);
cache_set('lingotek_' + $node->nid + '_link', $link, 'cache', time() + 900);
}
if (user_access('translate content') && $link['which_phase'] == 0 || user_access('review translations') && $link['which_phase'] != 0) {
drupal_set_message($link['message']);
}
}
}