When I create a node and add translations programatically. Tranlations are not linked to the node.

$language_list = array ('ru', 'uk');
    foreach($article_list as $article) {
      //$output .= print_r($article, 1);
      $node = entity_create('node', array('type' => 'article', 'title' => $article['en']['title'], 'language' => 'en'));
      $output .= $article['en']['title'] . '|<br>';
      $node->get('body')->setValue($article['en']['body']);
      foreach ($language_list as $language) {
        $translation = $node->getTranslation('ru');
        $output .= $article[$language]['title'] . '|<br>';
        if (empty($article[$language]['title'])) {
          continue;
        }
        $translation->get('title')->setValue($article[$language]['title']);
        $translation->get('body')->setValue($article[$language]['body']);
      }
      $node->save();
    }

Translations
Content list

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

victor-shelepen’s picture

$language_list = array ('ru', 'uk');
    foreach($article_list as $article) {
      //$output .= print_r($article, 1);
      $node = entity_create('node', array('type' => 'article', 'title' => $article['en']['title'], 'language' => 'en'));
      $output .= $article['en']['title'] . '|<br>';
      $node->get('body')->setValue($article['en']['body']);
      $node->save();
      foreach ($language_list as $language) {
        $translation = $node->getTranslation($language);
        $output .= $article[$language]['title'] . '|<br>';
        if (empty($article[$language]['title'])) {
          continue;
        }
        $translation->title = $article[$language]['title'];
        $translation->body = $article[$language]['body'];
        $translation->save();
      }
    }

I changed to. It does not attach translations.

Berdir’s picture

Component: translation_entity.module » content_translation.module
Category: Bug report » Support request
Status: Active » Fixed

What you are seeing in the user interface is the translation metadata, which you need to provide yurself if you're doing it programmatically.

See content_translation_entity_insert() for example, not that this might still change.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.