You are here

function lingotek_get_translated_node in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.5 lingotek.remote.inc \lingotek_get_translated_node()
1 call to lingotek_get_translated_node()
lingotek_download_document in ./lingotek.api.inc

File

./lingotek.api.inc, line 18

Code

function lingotek_get_translated_node($node, $drupal_language_code) {
  $tset = translation_node_get_translations($node->nid);
  if ($node->tnid == 0) {
    $node->tnid = $node->nid;
    db_update('node')
      ->fields(array(
      'tnid' => $node->nid,
    ))
      ->condition('nid', $node->nid)
      ->execute();
  }
  if (isset($tset[$drupal_language_code])) {
    $localized_node = node_load($tset[$drupal_language_code]->nid);
  }
  else {
    $localized_node = new stdClass();
    $localized_node->type = $node->type;
    node_object_prepare($localized_node);
    $localized_node->title = $node->title . ' (' . $drupal_language_code . ')';
    $localized_node->tnid = $node->tnid;
    $localized_node->language = $drupal_language_code;
    $localized_node->uid = $node->uid;
    $localized_node->name = $node->name;
    $localized_node->comment = $node->comment;
    $localized_node->promote = $node->promote;
    $localized_node->sticky = $node->sticky;
    $localized_node->status = $node->status;
    $localized_node->create_lingotek_document = FALSE;
    $lingotek_fields = variable_get('lingotek_enabled_fields');
    foreach ($lingotek_fields['node'][$localized_node->type] as $field_name) {
      $field = $node->{$field_name};
      $f = array();
      if (isset($field[$node->language])) {
        foreach ($field[$node->language] as $key => $value) {
          if (isset($value['format'])) {
            $f[$drupal_language_code][$key]['format'] = $value['format'];
          }
        }
      }
      $localized_node->{$field_name} = $f;
    }
    node_save($localized_node);
    lingotek_lingonode($localized_node->nid, 'node_sync_status', 'TARGET');
  }
  return $localized_node;
}