From cc9d58e2e8febb9190ffcd6c2bd8893bda6971b7 Mon Sep 17 00:00:00 2001 From: Bohdan Berezhniy Date: Fri, 9 Sep 2022 11:28:57 +0300 Subject: [PATCH] added translation sample file, fixed issue with import --- Files/Sample/translation.csv | 4 ++++ Model/Import/CustomerGroup.php | 24 ++++++++++++++------- composer.json | 38 +++++++++++++++++----------------- etc/di.xml | 9 ++++++-- 4 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 Files/Sample/translation.csv diff --git a/Files/Sample/translation.csv b/Files/Sample/translation.csv new file mode 100644 index 0000000..5a81786 --- /dev/null +++ b/Files/Sample/translation.csv @@ -0,0 +1,4 @@ +key_id,string,store_id,translate,locale +1,"You do not have any saved cards yet.",0,"Vous n'avez pas encore de carte sauvegardée",fr_FR +2,"Add a new saved card",1,"Ajoutez une nouvelle carte",fr_FR +,"New entity",1,"New entity translation",fr_FR diff --git a/Model/Import/CustomerGroup.php b/Model/Import/CustomerGroup.php index 82cb134..ea9f431 100755 --- a/Model/Import/CustomerGroup.php +++ b/Model/Import/CustomerGroup.php @@ -24,6 +24,8 @@ class CustomerGroup extends \Magento\ImportExport\Model\Import\Entity\AbstractEn const TABLE_Entity = 'translation'; + const CRC_STRING = 'crc_string'; + /** * Validation failure message template definitions * @@ -60,7 +62,8 @@ class CustomerGroup extends \Magento\ImportExport\Model\Import\Entity\AbstractEn self::STRING, self::STORE_ID, self::TRANSLATE, - self::LOCALE + self::LOCALE, + self::CRC_STRING ]; /** @@ -159,7 +162,7 @@ protected function _importData() } /** - * Save newsletter subscriber + * Save transl * * @return $this */ @@ -170,7 +173,7 @@ public function saveEntity() } /** - * Replace newsletter subscriber + * Replace translation * * @return $this */ @@ -181,7 +184,7 @@ public function replaceEntity() } /** - * Deletes newsletter subscriber data from raw data. + * Deletes translation data from raw data. * * @return $this */ @@ -207,7 +210,7 @@ public function deleteEntity() } /** - * Save and replace newsletter subscriber + * Save and replace translation * * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) @@ -228,6 +231,10 @@ protected function saveAndReplaceEntity() $this->getErrorAggregator()->addRowToSkip($rowNum); continue; } + + $this->countItemsCreated += (int) !isset($rowData[self::KEY_ID]); + $this->countItemsUpdated += (int) isset($rowData[self::KEY_ID]); + $rowTtile= $rowData[self::STRING]; $listTitle[] = $rowTtile; $entityList[$rowTtile][] = [ @@ -235,7 +242,8 @@ protected function saveAndReplaceEntity() self::STRING => $rowData[self::STRING], self::STORE_ID => $rowData[self::STORE_ID], self::TRANSLATE => $rowData[self::TRANSLATE], - self::LOCALE => $rowData[self::LOCALE] + self::LOCALE => $rowData[self::LOCALE], + self::CRC_STRING => crc32($rowData[self::STRING]) ]; } if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) { @@ -268,13 +276,15 @@ protected function saveEntityFinish(array $entityData, $table) $entityIn[] = $row; } } + if ($entityIn) { $this->_connection->insertOnDuplicate($tableName, $entityIn, [ self::KEY_ID, self::STRING, self::STORE_ID, self::TRANSLATE, - self::LOCALE + self::LOCALE, + self::CRC_STRING ]); } } diff --git a/composer.json b/composer.json index 4b27d05..fb58222 100755 --- a/composer.json +++ b/composer.json @@ -1,19 +1,19 @@ -{ - "name": "magefan/module-translation", - "description": "This module allowed admin user to change translations in admin panel", - "type": "magento2-module", - "version": "2.1.5.1", - "require": { - "magefan/module-community" : ">=2.1.10", - "magefan/module-crowdin-integration" : ">=2.0.0" - }, - "autoload": { - "files": [ "registration.php" ], - "psr-4": { - "Magefan\\Translation\\": "" - } - }, - "suggest": { - "magefan/module-translation-plus": "Translate product attributes on all store views in one click - visit magefan.com for more details" - } -} +{ + "name": "magefan/module-translation", + "description": "This module allowed admin user to change translations in admin panel", + "type": "magento2-module", + "version": "2.1.6", + "require": { + "magefan/module-community" : ">=2.1.11", + "magefan/module-crowdin-integration" : ">=2.0.0" + }, + "autoload": { + "files": [ "registration.php" ], + "psr-4": { + "Magefan\\Translation\\": "" + } + }, + "suggest": { + "magefan/module-translation-plus": "Translate product attributes on all store views in one click - visit magefan.com for more details" + } +} diff --git a/etc/di.xml b/etc/di.xml index 9c0888b..900daa8 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -42,6 +42,11 @@ - - + + + + Magefan_Translation + + +