diff -u b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php --- b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php @@ -19,4 +19,9 @@ /** + * Drupal 7 table names. + */ + const I18N_STRING_TABLE = 'i18n_string'; + + /** * {@inheritdoc} */ @@ -50,39 +55,22 @@ * {@inheritdoc} */ public function prepareRow(Row $row) { + parent::prepareRow($row); + + // Override language with ltlanguage. $language = $row->getSourceProperty('ltlanguage'); - $tid = $row->getSourceProperty('tid'); + $row->setSourceProperty('language', $language); - // If this row has been migrated it is a duplicate then skip it. - if ($this->idMap->lookupDestinationIds(['tid' => $tid, 'language' => $language])) { - return FALSE; - } + // Set the i18n string table for use in I18nQueryTrait. + $this->i18nStringTable = static::I18N_STRING_TABLE; // Save the translation for the property already in the row. $property_in_row = $row->getSourceProperty('property'); - $row->setSourceProperty($property_in_row . '_translated', $row->getSourceProperty('translation')); // Get the translation for the property not already in the row and save it // in the row. $property_not_in_row = ($property_in_row == 'name') ? 'description' : 'name'; - - // Get the translation, if one exists, for the property not already in the - // row. - $query = $this->select('i18n_string', 'i18n') - ->fields('i18n', ['lid']) - ->condition('i18n.property', $property_not_in_row) - ->condition('i18n.objectid', $tid); - $query->leftJoin('locales_target', 'lt', 'i18n.lid = lt.lid'); - $query->condition('lt.language', $language); - $query->addField('lt', 'translation'); - $results = $query->execute()->fetchAssoc(); - if (!$results) { - $row->setSourceProperty($property_not_in_row . '_translated', NULL); - } - else { - $row->setSourceProperty($property_not_in_row . '_translated', $results['translation']); - } - parent::prepareRow($row); + return $this->getPropertyNotInRowTranslation($row, $property_not_in_row, 'tid', $this->idMap); } /** diff -u b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php --- b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php @@ -132,7 +132,7 @@ 'description' => 'description value 1 (description_field)', 'weight' => 0, 'is_container' => '', - 'language' => 'en', + 'language' => 'fr', 'i18n_tsid' => '0', 'machine_name' => 'tags', 'tdlanguage' => 'und', @@ -150,7 +150,7 @@ 'description' => 'description value 1 (description_field)', 'weight' => 0, 'is_container' => '', - 'language' => 'en', + 'language' => 'fr', 'i18n_tsid' => '0', 'machine_name' => 'tags', 'tdlanguage' => 'und', @@ -168,7 +168,7 @@ 'description' => 'description value 3', 'weight' => 0, 'is_container' => '', - 'language' => 'en', + 'language' => 'zu', 'i18n_tsid' => '0', 'machine_name' => 'categories', 'tdlanguage' => 'und', @@ -186,7 +186,7 @@ 'description' => 'description value 5', 'weight' => 1, 'is_container' => '1', - 'language' => 'en', + 'language' => 'fr', 'i18n_tsid' => '0', 'machine_name' => 'categories', 'tdlanguage' => 'und', @@ -204,7 +204,7 @@ 'description' => 'description value 5', 'weight' => 1, 'is_container' => '1', - 'language' => 'en', + 'language' => 'fr', 'i18n_tsid' => '0', 'machine_name' => 'categories', 'tdlanguage' => 'und',