3

I am using the latest Entity Translation module in order to provide a couple of translatable fields for some of my content types. I have a content type which has a translatable field which is called "title_field".

I am using the Migrate module (version 2.0) in order to fill in the Drupal scheme with data from an old database. Normally, in a single language, the line would be:

$this->addFieldMapping('title_field','name')

Now the problem is that I have two translations of this field in my old database, which I want to create through the migration API.

$this->addFieldMapping('title_field','name_el')->arguments(array('language','el'));
$this->addFieldMapping('title_field','name_en')->arguments(array('language','en'));

Unfortunately this last one does not work. Any idea how I can go further with this?

0

I solved the problem by first doing the field translation manually for one node, and then using Node Export to see the actual code describing the node. Finally, I used the prepare function of the Migrate api to do the work manually.

function prepare($entity, stdClass $row){

    $entity->language = 'el';       
    $entity->title_field['el'][0]['value'] = $row->name;
    $entity->title_field['en'][0]['value'] = $row->name_en;
    $entity->translations = (object) array(
                    'original' => 'el',
                    'data' => array(
                            'el' => array(
                                    'entity_type' => 'node',
                                    'entity_id' => $entity->nid,
                                    'language' => 'el',
                                    'source' => '',
                                    'uid' => '0',
                                    'status' => '1',
                                    'translate' => '0',

                            ),
                            'en' => array(
                                    'entity_type' => 'node',
                                    'entity_id' => $entity->nid,
                                    'language' => 'en',
                                    'source' => 'el',
                                    'uid' => '1',
                                    'status' => '1',
                                    'translate' => '0',

                            ),
                    )
            );
 }
0

lefterav solution has a problem: in prepare() function, $entity is not yet saved, so $entity->nid is not set.

To solve this problem, I used complete() function:

public function complete($entity, stdClass $row) {
$entity->translations = (object) array(
  'original' => 'it',
  'data' => array(
    'it' => array(
      'entity_type' => 'node',
      'entity_id' => $entity->nid,
      'language' => 'it',
      'source' => '',
      'uid' => '1',
      'status' => '1',
      'translate' => '0',
    ),
    'en' => array(
      'entity_type' => 'node',
      'entity_id' => $entity->nid,
      'language' => 'en',
      'source' => 'it',
      'uid' => '1',
      'status' => '1',
      'translate' => '0',
    ),
  )
);
entity_save('node', $entity);


}
0

Import data in multiple languages

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.

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.