7

I come from read Using the new Drupal 8 Migration API / Module and Content Migration: CSV to Drupal 8 the process to create a migration is very clear and its works, but I can't find how to migrate content to a Multilingual site. In the Migrate API overview I can't find any information about this.

So, how can I migrate multilingual content?

UPDATE: I found an example: https://github.com/drupal/drupal/tree/8.3.x/core/modules/migrate/tests/modules/migrate_external_translated_test

I was able for the moment to migrate the english content but not the translations.

8
  • 1
    Disclaimer: I've never created a multi-lingual site before. I was able for the moment to migrate the english content Here is my multilingual newbie Q/suggestion, Can't you just pretend you just created the D8 site in English and now you want to make it multilingual?
    – No Sssweat
    Commented Jan 7, 2017 at 4:02
  • @NoSssweat I have a Multilingual site. I have in the CSV file the information in two languages and I need to create from this file the nodes in two languages (the node in english and his translation in french) Commented Jan 7, 2017 at 4:08
  • @NoSssweat can you post an answer with the steps to do it? Commented Jan 7, 2017 at 4:21
  • @NoSssweat text with format and text fields Commented Jan 7, 2017 at 4:42
  • Turns out I am way off, I hope these 2 videos helps you
    – No Sssweat
    Commented Jan 7, 2017 at 8:13

2 Answers 2

4

Migrate from CSV basics

As stated elsewhere, the migration code has only recently (as of 8.2.x or 8.3.x) seemed to settle down and there are loads of old, outdated and incorrect instructions in blog posts around the web. That being said, I've had about 75% success following the instructions on these two sets of blog posts from Lucas Hedding and Ada Hernández at Mtech.

There is an accompanying example codebase Lucas setup at Github that covers the basics of the first CSV blog post example, but it doesn't include any helpers with the image or file migrations.

There is another example repository from Wunderkraut that does include a CSV example migration with user, taxonomy, articles and images migration here:

Multilingual migration from CSV

I recommend starting with the CSV basics above, then moving to this section. You really need to have separate migration scripts for each language.

I got an additional 20% of the way there with this blog post, that outlines the details how to modify a migration yaml file to support multilingual content including, to enable translations: true in the destination section, to add the the langcode: field in the process section for proper multi-lingual entities (like nodes and terms), and to add the language: parameter for specific multi-language field processing.

I've found the most difficult part to be figuring out how to import file or image fields (the remaining 5% for me). Neither of the examples above demonstrate how to import image alt fields properly. In my case I have an image field that shares the image, but the alt attribute is translatable. I figured out how to import the basic alt field to the default language node on my own, but I'm having trouble getting the import to use the same fid but different alt text for other languages. The solution was figured out by user @Vasi by adding an additional field called content_translation_source on the process step of the foreign language migration YAML. More details with complete example here:

Additional Discussion

Finally, there is some discussion going on here as well:

3
  • 1
    I've created a follow-up question for my remaining problem here: drupal.stackexchange.com/questions/229750/… Commented Feb 27, 2017 at 2:52
  • thanks, I will test the code with the info in your answer Commented Feb 27, 2017 at 3:27
  • 1
    Turns out the missing key here is to add a content_translation_source field on the process section of the foreign language translation, the value should be set to the language code of the original language imported. See Vasi's answer on the link above. I'll also update my post to reflect this fix. Commented Mar 1, 2017 at 13:04
3
+50

you need both migration-tasks, the yml files in the migration folder:

migrate.migration.external_translated_test_node.yml
migrate.migration.external_translated_test_node_translation.yml

Then in the Plugin (MigrateExternalTranslatedTestSource.php), you need to read your .csv (in initializeIterator()) into the structure of the import array:

  /**
   * The data to import.
   *
   * @var array
   */
   protected $import = [
    ['name' => 'cat', 'title' => 'Cat', 'lang' => 'English'],
    ['name' => 'cat', 'title' => 'Chat', 'lang' => 'French'],
    ['name' => 'cat', 'title' => 'Gato', 'lang' => 'Spanish'],
    ['name' => 'dog', 'title' => 'Dog', 'lang' => 'English'],
    ['name' => 'dog', 'title' => 'Chien', 'lang' => 'French'],
    ['name' => 'monkey', 'title' => 'Monkey', 'lang' => 'English'],
   ];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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