Skip to content

Commit

Permalink
added translation sample file, fixed issue with import
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan Berezhniy committed Sep 9, 2022
1 parent b787d03 commit cc9d58e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Files/Sample/translation.csv
Original file line number Diff line number Diff line change
@@ -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
24 changes: 17 additions & 7 deletions Model/Import/CustomerGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
];

/**
Expand Down Expand Up @@ -159,7 +162,7 @@ protected function _importData()
}

/**
* Save newsletter subscriber
* Save transl
*
* @return $this
*/
Expand All @@ -170,7 +173,7 @@ public function saveEntity()
}

/**
* Replace newsletter subscriber
* Replace translation
*
* @return $this
*/
Expand All @@ -181,7 +184,7 @@ public function replaceEntity()
}

/**
* Deletes newsletter subscriber data from raw data.
* Deletes translation data from raw data.
*
* @return $this
*/
Expand All @@ -207,7 +210,7 @@ public function deleteEntity()
}

/**
* Save and replace newsletter subscriber
* Save and replace translation
*
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand All @@ -228,14 +231,19 @@ 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][] = [
self::KEY_ID => $rowData[self::KEY_ID],
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) {
Expand Down Expand Up @@ -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
]);
}
}
Expand Down
38 changes: 19 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
9 changes: 7 additions & 2 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
</argument>
</arguments>
</type>


<type name="Magento\ImportExport\Model\Import\SampleFileProvider">
<arguments>
<argument name="samples" xsi:type="array">
<item name="translation" xsi:type="string">Magefan_Translation</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit cc9d58e

Please sign in to comment.