This tutorial will explain, step-by-step, how to import multilingual data into Drupal. This is important for projects that require data to be imported, whether it's new data, data from an old site, or even from a desktop application.
There are a few modules that provide data import functionality, the most important one at the moment is Feeds. However, it's not currently able to import multilingual data.
An article on the Lullabot website gives an overview of importing data using Migrate and Table Wizard. This documentation page provides details on how to use these tools when importing multilingual content.
- First, it's necessary to install Drupal and also install and enable the following modules: Migrate and Migrate_i18n, you must also install and enable their dependencies: Table Wizard, Schema, Views, Migrate Extras, and Advanced Help.
Next, and very importantly, you must prepare the data to be loaded. Drupal must have access to the data using the "Table Wizard" module, so we have to create a table in the same database where Drupal installation has its own tables.
In our case, we are going to load a table of designers, which includes the name of each designer. The table is as follows:
id nid name lang 1 1 Todd Bracher es 2 1 Todd Bracher ca 3 1 Todd Bracher en 4 2 Jasper Morrison es 5 2 Jasper Morrison en 6 2 Jasper Morrison ca
- id: the primary key
- nid: the node identifier that must be the same for each designer in every language
- name: the name of the designer that can be different in every language
lang: the language code for i18n, in our case (en) English, (es) Spanish, (ca) Catalan
We name our table "load_designers" with the structure and data as described above.
Now go to Admin > Content management > Table Wizard. Select "Add existing tables" and it shows a list of tables present in the Drupal database. Select the table "load_designers" and click "Add tables". This action creates a new handler for the table and an associated view to query its data in the Views module. You can go to Admin > Site building > Views and take a look at its definition.
- It's time to create the load process, thanks to the Migrate module. Go to Admin > Content Management > Migrate and click on "Add content set". In the form that slides down write the name and "load_designers" and select the content type where you want to load data, in our case "Node:Designer" (a custom content type created using CCK, but thats another story) and as the data source select the Table Wizard "load_designers" that we've created before. Click "Add" and, in the next form, associate the necessary fields depending on your data and click "Submit".
Now we are ready to run the loading process, but in our case we want to load data in multiple languages and associate each node with its translations. This is what the Migrate_i18n module does. Go to Admin > Content Management > Migrate > Internationalization and select, in the first combo box, the field that contains the language identifier (i.e. "lang") and, in the second combo box, the field that identifies nodes across languages (that's "nid"). Click "Submit" and the bottom options will be activated.
In the bottom form you should see a list for each language active in the Drupal installation and each list with the different available language values (the contents of the "lang" column in the "load_designers" table). Then, select the corresponding language code for each language and click "Submit".
- Now we are ready to start loading the data into Drupal. Go to Admin > Content management > Migrate. Select "Import" from the "load_designers" process and click "Execute" to slide down the execution options. Simply click "Run".
- When the process finishes all data is loaded and we can see it at Admin > Content management > Content. To verify that all translations are loaded correctly, open a node and you should see three translations, corresponding to each language.