You are here

public function SocialContent::translate in Social Content 7.2

Translate a node to a set given languages

Parameters

object $node: The node to translate.

string $source_language: The source language to translate from.

string $langcodes: The languages to translate the node to.

1 call to SocialContent::translate()
SocialContent::import in ./social_content.class.inc
Do the import.

File

./social_content.class.inc, line 724
Social Content class.

Class

SocialContent
TODO: Table names should be a property for ease of change Separate this class into smaller classes.

Code

public function translate($node, $source_language, $langcodes) {
  $instances = field_info_instances('node', $node->type);
  $handler = entity_translation_get_handler('node', $node);
  foreach ($langcodes as $langcode) {
    $values = array();
    foreach ($instances as $instance) {
      $field_name = $instance['field_name'];
      if (!empty($node->{$field_name})) {
        $values[$field_name][$langcode] = !empty($node->{$field_name}[$source_language]) ? $node->{$field_name}[$source_language] : $node->{$field_name}[LANGUAGE_NONE];
      }
    }
    $translation = array(
      'translate' => 1,
      'status' => 1,
      'language' => $langcode,
      'source' => $source_language,
    );
    $handler
      ->setTranslation($translation, $values);
    field_attach_update('node', $node);
  }
}