Merge pull request #1143 from vishal-singh-webkul/gli-2185
Fixed: Error on AdminTranslationController while translating modules, also optimized the translation process for the modules.
This commit is contained in:
@@ -954,7 +954,7 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
*
|
||||
* @throws PrestaShopException
|
||||
*/
|
||||
protected function findAndWriteTranslationsIntoFile($file_name, $files, $theme_name, $module_name, $dir = false)
|
||||
protected function findAndWriteTranslationsIntoFile($file_name, $files, $theme_name, $module_name, $dir = false, $copyExistingTranslations = false)
|
||||
{
|
||||
// These static vars allow to use file to write just one time.
|
||||
static $cache_file = array();
|
||||
@@ -964,7 +964,12 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
|
||||
// Set file_name in static var, this allow to open and wright the file just one time
|
||||
if (!isset($cache_file[$theme_name.'-'.$file_name])) {
|
||||
require $file_name;
|
||||
if (file_exists($file_name)) {
|
||||
require $file_name;
|
||||
} else {
|
||||
$_MODULE = array();
|
||||
}
|
||||
|
||||
$module_existing_translations = $_MODULE;
|
||||
$str_write = '';
|
||||
$cache_file[$theme_name.'-'.$file_name] = true;
|
||||
@@ -1010,25 +1015,26 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
}
|
||||
|
||||
if (array_key_exists($post_key, $_POST) && !in_array($pattern, $array_check_duplicate)) {
|
||||
$array_check_duplicate[] = $pattern;
|
||||
if ($_POST[$post_key] == '') {
|
||||
continue;
|
||||
}
|
||||
$array_check_duplicate[] = $pattern;
|
||||
$str_write .= '$_MODULE['.$pattern.'] = \''.pSQL(str_replace(array("\r\n", "\r", "\n"), ' ', $_POST[$post_key])).'\';'."\n";
|
||||
$this->total_expression++;
|
||||
}
|
||||
}
|
||||
foreach ($module_existing_translations as $key => $value) {
|
||||
if (!in_array('\''.$key.'\'', $array_check_duplicate)) {
|
||||
$str_write .= '$_MODULE[\''.$key.'\'] = \''.pSQL(str_replace(array("\r\n", "\r", "\n"), ' ', $value)).'\';'."\n";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($cache_file[$theme_name.'-'.$file_name]) && $str_write != "<?php\n\nglobal \$_MODULE;\n\$_MODULE = array();\n") {
|
||||
if ($copyExistingTranslations) {
|
||||
foreach ($module_existing_translations as $key => $value) {
|
||||
if (!in_array('\''.$key.'\'', $array_check_duplicate)) {
|
||||
$str_write .= '$_MODULE[\''.$key.'\'] = \''.pSQL(str_replace(array("\r\n", "\r", "\n"), ' ', $value)).'\';'."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($cache_file[$theme_name.'-'.$file_name])) {
|
||||
file_put_contents($file_name, $str_write);
|
||||
}
|
||||
}
|
||||
@@ -1056,6 +1062,8 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
unset($files[$key]);
|
||||
} elseif ($type_clear === 'directory' && (!is_dir($path.$file) || in_array($file, $arr_exclude))) {
|
||||
unset($files[$key]);
|
||||
} else if ($file == 'index.php') {
|
||||
unset($files[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1468,8 +1476,15 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
$arr_files = $this->getAllModuleFiles($modules, null, $this->lang_selected->iso_code, true);
|
||||
|
||||
// Find and write all translation modules files
|
||||
foreach ($arr_files as $value) {
|
||||
$this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir']);
|
||||
foreach ($arr_files as $key => $value) {
|
||||
$copyExistingTranslations = false;
|
||||
if (!isset($arr_files[$key + 1])
|
||||
|| ($arr_files[$key + 1]['module'] != $value['module'])
|
||||
) {
|
||||
$copyExistingTranslations = true;
|
||||
}
|
||||
|
||||
$this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir'], $copyExistingTranslations);
|
||||
}
|
||||
|
||||
// Clear modules cache
|
||||
|
||||
Reference in New Issue
Block a user