In this page, we will see how to handle an entityreference field in content type 2 referencing a content of content type 1 without having the id of the target, only its title.

And of course in all the languages we want.

Principle

For the main language import, we will be using an entityfieldquery to get the id of the content of content type 1 in the main language.
For the other languages import, we will use the main language import to be sure of the id of the target.

content type 1 fr <--- content type 1 en
^
content type 2 fr ---> content type 2 en

Note:

The management of references can be made easily with the use of sourceMigration() in the field mappings. If you can have columns with the CSV ID of the referenced targets.

content_type_2.inc

class ContentType2Migration extends my_module_Basic_Migration {
  public function __construct($arguments) {
    parent::__construct($arguments);
    $this->description = t('Import ContentType2 CSV-file');
    $columns = array(
      // "Source": ('Fieldname', 'Description')
       0 => array('csv_id', t('CSV id')),
       1 => array('content_type_1_title', t('ContentType1 Title')),
       2 => array('content_type_2_title', t('ContentType2 Title')),
       ...
    );
    $this->source = new MigrateSourceCSV(
      DRUPAL_ROOT . '/' . drupal_get_path('module', 'my_module') . '/data_sources/Content_type_2/content_type_2.' . $arguments['language_prefix'] . '.csv',
      $columns,
      array(
        'header_rows' => 1,
        'embedded_newlines' => TRUE
      )
    );
    $this->destination = new MigrateDestinationNode('content_type_2');
    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'csv_id' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        )
      ),
      MigrateDestinationNode::getKeySchema()
    );
    if ($arguments['language_prefix'] != 'en') {
      $this->addSoftDependencies(array('ContentType2_en'));
    }
    $this->addHardDependencies(array('ContentType1_' . $arguments['language_prefix']));

    // Mapped fields
    $this->addFieldMapping('title', 'content_type_2_title')
      ->defaultValue('');
    
    $this->addFieldMapping('language')
      ->defaultValue(str_replace('_', '-', $arguments['language_prefix']));
    // tnid
    if ($arguments['language_prefix'] != 'en') {
      $this->addFieldMapping('tnid', 'csv_id')
        ->sourceMigration('ContentType2_en');
    }

    // ContentType1 reference
    if ($arguments['language_prefix'] == 'en') {
      $this->addFieldMapping('field_ContentType1', 'content_type_1_title')
        ->callbacks(array($this, 'getcontenttype1nid'));
    }
    else {
      $this->addFieldMapping('field_ContentType1', 'csv_id')
        ->callbacks(array($this, 'getcontenttype1nid'));
    }
  }

  // Return the ContentType1 nid from which this ContentType2 is related in the same language.
  protected function getcontenttype1nid($value) {
    $language = str_replace('_', '-', $this->arguments['language_prefix']);

    if ($language == 'en') {
      $query = new EntityFieldQuery();
      $node_list = $query->entityCondition('entity_type', 'node')
        ->propertyCondition('type', 'content_type_1')
        ->propertyCondition('language', 'en')
        ->propertyCondition('title', $value)
        ->execute();

      if (isset($node_list['node'])) {
        $node_nid_list = array_keys($node_list['node']);
        $value = $node_nid_list['0'];
      }
    }
    else {
      // Get the ContentType2 en.
      $ContentType2_en_tnid = $this->gettnid($value);

      // Get the ContentType1 en.
      $ContentType2_en = node_load($ContentType2_en_tnid);
      $ContentType1_en_nid = $ContentType2_en->field_ContentType1['en'][0]['target_id'];

      // Get the ContentType1 in the other language.
      $query = new EntityFieldQuery();
      $node_list = $query->entityCondition('entity_type', 'node')
        ->propertyCondition('type', 'content_type_1')
        ->propertyCondition('language', str_replace('_', '-', $this->arguments['language_prefix']))
        ->propertyCondition('tnid', $ContentType1_en_nid)
        ->execute();
      if (isset($node_list['node'])) {
        $node_nid_list = array_keys($node_list['node']);
        $value = $node_nid_list['0'];
      }
    }

    return $value;
  }

 public function complete($entity, stdClass $row) {
    // Put the tnid for english content after it is created.
    if ($this->arguments['language_prefix'] == 'en') {
      $entity->tnid = $entity->nid;
      node_save($entity);
    }
  }
}

Example files:

content_type_2.en.csv

"CSV ID","Title content type 1", "Title content type 2"
1,"Title 1","Title CT2 1"
2,"Title 2","Title CT2 2"
3,"Title 3","Title CT2 3"

content_type_2.fr.csv

"CSV ID","Title content type 1", "Title content type 2"
1,"Titre 1","Titre TC2 1"
2,"Titre 2","Titre TC2 2"
3,"Titre 3","Titre TC2 3"