Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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();
}
Comment | File | Size | Author |
---|---|---|---|
Screenshot from 2014-07-24 09:57:45.png | 67.99 KB | victor-shelepen | |
Screenshot from 2014-07-24 10:10:20.png | 130.11 KB | victor-shelepen |
Comments
Comment #1
victor-shelepen CreditAttribution: victor-shelepen commentedI changed to. It does not attach translations.
Comment #2
BerdirWhat 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.