Multilingual Migration from Drupal 7 to Drupal 8

10 Nov 2017
D7 to D8 Multilingual Migration

Today, We will see multilingual migration of content from Drupal 7 to Drupal 8. In this article we will share the related code as well. Our objective is to demonstrate the migration of multilingual content from Drupal 7 site to Drupal 8 site. First of all, we need to have a Drupal 7 multilingual site, if you want to see how to setup a multilingual site in Drupal 7, check this post. Once we have multilingual content in Drupal 7 site. We need to do the site building of Drupal 8 with multilingual capabilities. Check this post for more details.

Multilingual Migration Basics

Migrate API helps us migrate data from a given source to a given destination. It maintains a map of old records and the new records and uses it do cool stuff like updating changed records, rolling back, etc. You can access the codebase + database from github account, download and read the README.txt file and try yourself.

Migrations in Drupal 8: Introduction

  1. Define a custom module to contain our migration-related code and migration definitions (optional).
  2. Write YAML files to define migrations and migration groups.
  3. Use drush commands to see the status of and execute migrations.

Things we need to do for Multilingual Migration

  1. First, we migrate things in the base language.
  2. Next, we migrate the translations!

Which means in case of multilingual migration we need to create .yml files for each language.

Here in the example shared on github, we have created a custom module "node_migrate". And just like any migration in Drupal 8 we have created a config/install directory and inside that we have migrate_plus.migration.node_migrate.yml and migrate_plus.migration.node_migrate_hi.yml. These are for the two language (English and Hindi) in which we have content in Drupal 7 site, here we used article content type for migration.

Migration YML

Here you can see, we have the base migration yml file and the second one is for translation. In the second one we have used translations: true in source and destination.

Migration YML Hindi

Now we need to create a php file in node_migrate/src/Plugin/migrate/source/D7article.php. This will have the required query and data for the migration.