6

I'm running a multilingual migration of events (which are stored as nodes) that have keywords on them where there are keywords (stored as terms). The keywords should be stored in a multilingual tags vocabulary.

The source is a REST API, and what I have for the keyword data looks like this:

array (
 'id' => 'yso:p360',
 'alt_labels' => 
 array (
 ),
 'created_time' => '2014-06-23T11:37:29.198000Z',
 'last_modified_time' => '2014-06-23T11:37:29.198000Z',
 'aggregate' => false,
 'deprecated' => false,
 'n_events' => 11709,
 'data_source' => 'yso',
 'image' => NULL,
 'name' => 
 array (
   'fi' => 'kulttuuritapahtumat',
   'en' => 'cultural events',
   'sv' => 'kulturevenemang',
 ),
 '@id' => 'https://api.hel.fi/linkedevents/v1/keyword/yso:p360/',
 '@context' => 'http://schema.org',
 '@type' => 'Keyword',
)

Is there some way to use for example EntityGenerate to create all the translations of the tags when importing the original languages of the events that has these tags?

Note:

I would like to avoid migrating all the keywords first. We only import a subset of the events, and we are only interested in the keywords that are used by those events.

The normal way of D8 migrations with multilingual sources is to create a configuration for each translation. This doesn't work in our case, as I chose to use entity_generate for the tags. If you have another suggestion, I am interested.

0

I'm missing some informations for all understand your problem but, to migrate an object which have many translation you need: Create the initial entity in the source language of your choose and add translation to this entity. For example, for a taxonomy term:

$default_language = "en";
$other_languages = ["fi", "sv"];

$term = \Drupal\taxonomy\Entity\Term::create([
  'vid' => 'my_vocabulary',
  'name' => $my_importer_object['name'][$default_language],
]);

$term->save();

foreach($other_languages as $language) {
  $term_object = [
    'vid' => 'my_vocabulary',
    'name' => $my_importer_object['name'][$language],
  ];
  $term->addTranslation($language, $term_object);

  $term->save();
}

Like it's a taxonomy term, it will be reference in your object like a entity references, with its tid. The link between translated version of the term and translated version of the node will be the language. If the term exist in the language of the node, Drupal 8 will used it automatically. If the term isn't translated in the language, Drupal will use the original language of the term, in which it had been initially created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.