[-] BO : #PSCFV-2336 : Now importation of lang pack is moving in selected themes
This commit is contained in:
@@ -120,9 +120,20 @@
|
||||
<img src="../img/admin/import.gif" />{l s='Import a language pack manually'}
|
||||
</legend>
|
||||
<div id="submitImportContent">
|
||||
{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!'}<br /><br />
|
||||
{l s='Language pack to import:'} <input type="file" name="file" /> <input type="submit" value="{l s='Import'}" name="submitImport" class="button" /></p>
|
||||
<p>
|
||||
{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!'}
|
||||
</p>
|
||||
<p><label for="importLanguage">{l s='Language pack to import:'}</label><input type="file" name="file" id="importLanguage"/> </p>
|
||||
<p>
|
||||
<label for="selectThemeForImport">{l s='Select yours themes:'}</label>
|
||||
<select name="theme[]" id="selectThemeForImport" {if count($themes) > 1}multiple="multiple"{/if} >
|
||||
{foreach $themes as $theme}
|
||||
<option value="{$theme->directory}" selected="selected">{$theme->name} </option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</p>
|
||||
<p class="margin-form"><input type="submit" value="{l s='Import'}" name="submitImport" class="button" /></p>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user