diff --git a/Controller/AdminController.php b/Controller/AdminController.php index 2c72c84..6da2bca 100644 --- a/Controller/AdminController.php +++ b/Controller/AdminController.php @@ -22,8 +22,15 @@ public function showPage() { // Is the module active ? $translationInUse = is_dir($this->getTranslationDir()); - - return $this->render('Translation/translation', ['in_use' => $translationInUse]); + $ext = Translation::getConfigValue('extension'); + $error = $this->getRequest()->get('error'); + + return $this->render('Translation/translation', + [ + 'in_use' => $translationInUse, + 'ext' => $ext, + 'error' => $error + ]); } public function setExtensionAction() diff --git a/Controller/ImportController.php b/Controller/ImportController.php index 8504d69..ac67198 100644 --- a/Controller/ImportController.php +++ b/Controller/ImportController.php @@ -13,9 +13,22 @@ use Thelia\Controller\Admin\BaseAdminController; use Thelia\Tools\URL; use Translation\Translation; +use \RecursiveDirectoryIterator; +use \RecursiveIteratorIterator; class ImportController extends BaseAdminController { + public function getFilePath($dirPath, $fileName) { + $oDirectory = new RecursiveDirectoryIterator($dirPath); + $oIterator = new RecursiveIteratorIterator($oDirectory); + foreach($oIterator as $oFile) { + if ($oFile->getFilename() == $fileName) { + return $oFile->getPath(); + } + } + return false; + } + public function importAction() { $path = Translation::TRANSLATIONS_DIR . 'tmp'; @@ -32,20 +45,35 @@ public function importAction() /** @var UploadedFile $importFile */ $importFile = $this->getRequest()->files->get('file'); + if ($importFile) { + $originalExt = $importFile->getClientOriginalExtension(); + $originalName = $importFile->getClientOriginalName(); - $today = new \DateTime(); - $fileName = 'translation-import-' . $today->format('Y-m-d_H-i-s') . '.zip'; + if ($originalExt == 'zip') { - copy($importFile , $path . DS . $fileName); + $today = new \DateTime(); + $fileName = 'translation-import-' . $today->format('Y-m-d_H-i-s') . '.zip'; - $zip = new \ZipArchive(); - $zip->open($path . DS . $fileName); - $zip->extractTo($path); - $zip->close(); + copy($importFile , $path . DS . $fileName); - unlink($path . DS . $fileName); - $this->moveDirectory($path , Translation::TRANSLATIONS_DIR . $ext , $ext); - Translation ::deleteTmp(); + $zip = new \ZipArchive(); + $zip->open($path . DS . $fileName); + $zip->extractTo($path); + $zip->close(); + + unlink($path . DS . $fileName); + $this->moveDirectory($path , Translation::TRANSLATIONS_DIR . $ext , $ext); + Translation ::deleteTmp(); + } else { + $filePath = $this->getFilePath(Translation::TRANSLATIONS_DIR . $ext, $originalName); + if (!$filePath) + return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/translation', ['error' => '1'])); + copy($importFile, $filePath . DS . $originalName); + + } + } + else + return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/translation', ['error' => '2'])); return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/translation')); } @@ -87,4 +115,3 @@ protected function mergeDirectory($oldDir , $newDir) } } } - diff --git a/I18n/backOffice/default/en_US.php b/I18n/backOffice/default/en_US.php index ac39a46..07853b2 100644 --- a/I18n/backOffice/default/en_US.php +++ b/I18n/backOffice/default/en_US.php @@ -19,6 +19,8 @@ instead of Thelia\'s integrated translation system. You can export all the texts to be translated, use an external translation tool to translate them, and import the result that will be used instead of standard Thelia translations.' => 'This module implements a translation system which uses standard format files (PO, Xlif) instead of Thelia\'s integrated translation system. You can export all the texts to be translated, use an external translation tool to translate them, and import the result that will be used instead of standard Thelia translations.', 'Translations' => 'External translations', + 'Please import a valid file.' => 'Please import a valid file.', + 'Failed to update this file, this file doesn\'t seem to exist in this translation system.' => 'Failed to update this file, this file doesn\'t seem to exist in this translation system.', 'You\'re using the external translations. Click the revert button to go back to standard Thelia translation system.' => 'You\'re using the external translations. Click the revert button to go back to standard Thelia translation system.', 'You\'re using the standard Thelia translation system. Please import translations to use the external translations' => 'You\'re using the standard Thelia translation system. Please import translations to use the external translations', 'Zip the folder you have exported before with exactly the same structure and with your translation modification. And upload it here.' => 'Zip the folder you have exported before with exactly the same structure and with your translation modification. And upload it here.', diff --git a/I18n/backOffice/default/fr_FR.php b/I18n/backOffice/default/fr_FR.php index c8193ff..a341381 100644 --- a/I18n/backOffice/default/fr_FR.php +++ b/I18n/backOffice/default/fr_FR.php @@ -19,6 +19,8 @@ instead of Thelia\'s integrated translation system. You can export all the texts to be translated, use an external translation tool to translate them, and import the result that will be used instead of standard Thelia translations.' => 'Ce module permet d\'utiliser un système de traduction qui s\'appuie sur des fichiers respectant un format standard (PO, Xlif) au lieu du système de traduction intégré de Thelia. Vous pouvez ainsi exporter tous les textes à traduire, utiliser des outils de traduction externes pour les traduire, et importer les résultats qui seront pris en compte immédiatement.', 'Translations' => 'Traductions externes', + 'Please import a valid file.' => 'Merci d\'importer un fichier valide.', + 'Failed to update this file, this file doesn\'t seem to exist in this translation system.' => 'Echec de la mise à jour de ce fichier, ce fichier ne semble pas exister dans ce système de traduction.', 'You\'re using the external translations. Click the revert button to go back to standard Thelia translation system.' => 'Vous utilisez le système de traduction externe. Cliquez le bouton "Retour au standard" pour revenir au système de traduction standard de Thelia.', 'You\'re using the standard Thelia translation system. Please import translations to use the external translations' => 'Vous utilisez le système de traduction standard de Thelia. Importez des traductions pour utiliser le système de traduction externe.', 'Zip the folder you have exported before with exactly the same structure and with your translation modification. And upload it here.' => 'Compressez au format Zip le dossier qui contient les fichiers traduits avec exactement la même structure que le fichier exporté, et téléversez-le ici.', diff --git a/templates/backOffice/default/Translation/translation.html b/templates/backOffice/default/Translation/translation.html index caf8245..62e34f8 100644 --- a/templates/backOffice/default/Translation/translation.html +++ b/templates/backOffice/default/Translation/translation.html @@ -15,6 +15,18 @@ + {if $error} +