From 2f70ef1186ccc8d40b43bad8b5f8a15b3466f189 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Tue, 15 May 2012 14:45:52 +0000 Subject: [PATCH] [-] BO : #PSCFV-2336 : Now importation of lang pack is moving in selected themes --- .../translations/helpers/view/main.tpl | 17 ++++++-- .../admin/AdminTranslationsController.php | 43 ++++++++++++++++++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/translations/helpers/view/main.tpl b/admin-dev/themes/default/template/controllers/translations/helpers/view/main.tpl index bb3a26cae..c0ea9dd8a 100644 --- a/admin-dev/themes/default/template/controllers/translations/helpers/view/main.tpl +++ b/admin-dev/themes/default/template/controllers/translations/helpers/view/main.tpl @@ -120,9 +120,20 @@ {l s='Import a language pack manually'}
- {l s='If the name format is: isocode.gzip (e.g. us.gzip) and the language corresponding to this package does not exist, it will automatically be created.'} - {l s='Be careful, as this will replace all existing data for the destination language!'}

- {l s='Language pack to import:'}  

+

+ {l s='If the name format is: isocode.gzip (e.g. us.gzip) and the language corresponding to this package does not exist, it will automatically be created.'} + {l s='Be careful, as this will replace all existing data for the destination language!'} +

+

 

+

+ + +

+

diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index 51208ea4b..318d17a7e 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -444,6 +444,43 @@ class AdminTranslationsControllerCore extends AdminController } } + /** + * Move theme translations in selected themes + * + * @param array $files + * @param array $themes_selected + */ + public function checkAndAddThemesFiles($files, $themes_selected) + { + foreach ($files as $file) + { + // Check if file is a file theme + if (preg_match('#^themes\/([a-z0-9]+)\/lang\/#Ui', $file['filename'], $matches)) + { + $slash_pos = strrpos($file['filename'], '/'); + $name_file = substr($file['filename'], -(strlen($file['filename']) - $slash_pos - 1)); + $name_default_theme = $matches[1]; + $deleted_old_theme = false; + + // Get the old file theme + if (file_exists(_PS_THEME_DIR_.'lang/'.$name_file)) + $theme_file_old = _PS_THEME_DIR_.'lang/'.$name_file; + else + { + $deleted_old_theme = true; + $theme_file_old = str_replace(self::DEFAULT_THEME_NAME, $name_default_theme, _PS_THEME_DIR_.'lang/'.$name_file); + } + + // Move the old file theme in the new folder + foreach ($themes_selected as $theme_name) + copy($theme_file_old, str_replace($name_default_theme, $theme_name, $theme_file_old)); + + if ($deleted_old_theme) + @unlink($theme_file_old); + } + } + } + public function submitImportLang() { if (!isset($_FILES['file']['tmp_name']) || !$_FILES['file']['tmp_name']) @@ -452,10 +489,12 @@ class AdminTranslationsControllerCore extends AdminController { $gz = new Archive_Tar($_FILES['file']['tmp_name'], true); $iso_code = str_replace('.gzip', '', $_FILES['file']['name']); + $themes_selected = Tools::getValue('theme', array(self::DEFAULT_THEME_NAME)); $files_list = $gz->listContent(); if ($gz->extract(_PS_TRANSLATIONS_DIR_.'../', false)) { $this->checkAndAddMailsFiles($iso_code, $files_list); + $this->checkAndAddThemesFiles($files_list, $themes_selected); if (Validate::isLanguageFileName($_FILES['file']['name'])) { if (!Language::checkAndAddLanguage($iso_code)) @@ -919,7 +958,7 @@ class AdminTranslationsControllerCore extends AdminController $this->themes = Theme::getThemes(); // Get folder name of theme - if ($theme = Tools::getValue('theme')) + if (($theme = Tools::getValue('theme')) && !is_array($theme)) $this->theme_selected = Tools::safeOutput($theme); else $this->theme_selected = self::DEFAULT_THEME_NAME; @@ -928,7 +967,7 @@ class AdminTranslationsControllerCore extends AdminController define('_PS_THEME_SELECTED_DIR_', _PS_ROOT_DIR_.'/themes/'.$this->theme_selected.'/'); // Get type of translation - if ($type = Tools::getValue('type')) + if (($type = Tools::getValue('type')) && !is_array($type)) $this->type_selected = strtolower(Tools::safeOutput($type)); // Get selected language