// Changed translation tool behavior with dev mode and overrides
This commit is contained in:
@@ -60,15 +60,15 @@
|
|||||||
<form method="get" action="index.php" id="typeTranslationForm">
|
<form method="get" action="index.php" id="typeTranslationForm">
|
||||||
<input type="hidden" name="controller" value="AdminTranslations" />
|
<input type="hidden" name="controller" value="AdminTranslations" />
|
||||||
<input type="hidden" name="lang" id="translation_lang" value="0" />
|
<input type="hidden" name="lang" id="translation_lang" value="0" />
|
||||||
<select name="type" style="float:left; margin-right:10px;">
|
<select name="type" style="float:left;margin-right:10px">
|
||||||
{foreach $translations_type as $type => $array}
|
{foreach $translations_type as $type => $array}
|
||||||
<option value="{$type}">{$array.name} </option>
|
<option value="{$type}">{$array.name}</option>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
<select name="theme" style="float:left; margin-right:10px;">
|
<select name="theme" style="float:left;margin-right:10px">
|
||||||
|
<option value="">{l s='Core (no theme selected)'}</option>
|
||||||
{foreach $themes as $theme}
|
{foreach $themes as $theme}
|
||||||
|
<option value="{$theme->directory}" {if $id_theme_current == $theme->id}selected=selected{/if}>{$theme->name}</option>
|
||||||
<option value="{$theme->directory}" {if $id_theme_current == $theme->id}selected=selected{/if}>{$theme->name} </option>
|
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
{foreach $languages as $language}
|
{foreach $languages as $language}
|
||||||
|
|||||||
@@ -788,9 +788,6 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
static $str_write = '';
|
static $str_write = '';
|
||||||
static $array_check_duplicate = array();
|
static $array_check_duplicate = array();
|
||||||
|
|
||||||
// Default translations and Prestashop overriding themes are distinguish
|
|
||||||
$is_default = $theme_name === self::DEFAULT_THEME_NAME ? true : false;
|
|
||||||
|
|
||||||
// Set file_name in static var, this allow to open and wright the file just one time
|
// 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]))
|
if (!isset($cache_file[$theme_name.'-'.$file_name]))
|
||||||
{
|
{
|
||||||
@@ -827,16 +824,16 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
|
|
||||||
foreach ($matches as $key)
|
foreach ($matches as $key)
|
||||||
{
|
{
|
||||||
if ($is_default)
|
if ($theme_name)
|
||||||
{
|
|
||||||
$post_key = md5(strtolower($module_name).'_'.self::DEFAULT_THEME_NAME.'_'.strtolower($template_name).'_'.md5($key));
|
|
||||||
$pattern = '\'<{'.strtolower($module_name).'}prestashop>'.strtolower($template_name).'_'.md5($key).'\'';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$post_key = md5(strtolower($module_name).'_'.strtolower($theme_name).'_'.strtolower($template_name).'_'.md5($key));
|
$post_key = md5(strtolower($module_name).'_'.strtolower($theme_name).'_'.strtolower($template_name).'_'.md5($key));
|
||||||
$pattern = '\'<{'.strtolower($module_name).'}'.strtolower($theme_name).'>'.strtolower($template_name).'_'.md5($key).'\'';
|
$pattern = '\'<{'.strtolower($module_name).'}'.strtolower($theme_name).'>'.strtolower($template_name).'_'.md5($key).'\'';
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$post_key = md5(strtolower($module_name).'_'.self::DEFAULT_THEME_NAME.'_'.strtolower($template_name).'_'.md5($key));
|
||||||
|
$pattern = '\'<{'.strtolower($module_name).'}prestashop>'.strtolower($template_name).'_'.md5($key).'\'';
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists($post_key, $_POST) && !empty($_POST[$post_key]) && !in_array($pattern, $array_check_duplicate))
|
if (array_key_exists($post_key, $_POST) && !empty($_POST[$post_key]) && !in_array($pattern, $array_check_duplicate))
|
||||||
{
|
{
|
||||||
@@ -900,9 +897,6 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
// added for compatibility
|
// added for compatibility
|
||||||
$GLOBALS[$name_var] = array_change_key_case($GLOBALS[$name_var]);
|
$GLOBALS[$name_var] = array_change_key_case($GLOBALS[$name_var]);
|
||||||
|
|
||||||
// Default translations and Prestashop overriding themes are distinguish
|
|
||||||
$is_default = $theme_name === self::DEFAULT_THEME_NAME ? true : false;
|
|
||||||
|
|
||||||
// Thank to this var similar keys are not duplicate
|
// Thank to this var similar keys are not duplicate
|
||||||
// in AndminTranslation::modules_translations array
|
// in AndminTranslation::modules_translations array
|
||||||
// see below
|
// see below
|
||||||
@@ -929,8 +923,11 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
|
|
||||||
foreach ($matches as $key)
|
foreach ($matches as $key)
|
||||||
{
|
{
|
||||||
$module_key = '<{'.Tools::strtolower($module_name).'}'.
|
$md5_key = md5($key);
|
||||||
strtolower($is_default ? 'prestashop' : $theme_name).'>'.Tools::strtolower($template_name).'_'.md5($key);
|
$module_key = null;
|
||||||
|
if ($theme_name)
|
||||||
|
$module_key = '<{'.Tools::strtolower($module_name).'}'.strtolower($theme_name).'>'.Tools::strtolower($template_name).'_'.$md5_key;
|
||||||
|
$default_key = '<{'.Tools::strtolower($module_name).'}prestashop>'.Tools::strtolower($template_name).'_'.$md5_key;
|
||||||
// to avoid duplicate entry
|
// to avoid duplicate entry
|
||||||
if (!in_array($module_key, $array_check_duplicate))
|
if (!in_array($module_key, $array_check_duplicate))
|
||||||
{
|
{
|
||||||
@@ -938,8 +935,10 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
if (!isset($this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad']))
|
if (!isset($this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad']))
|
||||||
$this->total_expression++;
|
$this->total_expression++;
|
||||||
|
|
||||||
if (array_key_exists($module_key, $GLOBALS[$name_var]))
|
if ($module_key && array_key_exists($module_key, $GLOBALS[$name_var]))
|
||||||
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = html_entity_decode($GLOBALS[$name_var][$module_key], ENT_COMPAT, 'UTF-8');
|
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = html_entity_decode($GLOBALS[$name_var][$module_key], ENT_COMPAT, 'UTF-8');
|
||||||
|
elseif (array_key_exists($default_key, $GLOBALS[$name_var]))
|
||||||
|
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = html_entity_decode($GLOBALS[$name_var][$default_key], ENT_COMPAT, 'UTF-8');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = '';
|
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = '';
|
||||||
@@ -1128,7 +1127,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
'front' => array(
|
'front' => array(
|
||||||
'name' => $this->l('Front Office translations'),
|
'name' => $this->l('Front Office translations'),
|
||||||
'var' => '_LANG',
|
'var' => '_LANG',
|
||||||
'dir' => _PS_THEME_SELECTED_DIR_.'lang/',
|
'dir' => defined('_PS_THEME_SELECTED_DIR_') ? _PS_THEME_SELECTED_DIR_.'lang/' : '',
|
||||||
'file' => $this->lang_selected->iso_code.'.php'
|
'file' => $this->lang_selected->iso_code.'.php'
|
||||||
),
|
),
|
||||||
'back' => array(
|
'back' => array(
|
||||||
@@ -1153,33 +1152,28 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
'name' => $this->l('Installed modules translations'),
|
'name' => $this->l('Installed modules translations'),
|
||||||
'var' => '_MODULES',
|
'var' => '_MODULES',
|
||||||
'dir' => _PS_MODULE_DIR_,
|
'dir' => _PS_MODULE_DIR_,
|
||||||
'file' => '',
|
'file' => ''
|
||||||
'override' => array(
|
|
||||||
'dir' => _PS_THEME_SELECTED_DIR_.'modules/',
|
|
||||||
'file' => ''
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
'pdf' => array(
|
'pdf' => array(
|
||||||
'name' => $this->l('PDF translations'),
|
'name' => $this->l('PDF translations'),
|
||||||
'var' => '_LANGPDF',
|
'var' => '_LANGPDF',
|
||||||
'dir' => _PS_TRANSLATIONS_DIR_.$this->lang_selected->iso_code.'/',
|
'dir' => _PS_TRANSLATIONS_DIR_.$this->lang_selected->iso_code.'/',
|
||||||
'file' => 'pdf.php',
|
'file' => 'pdf.php'
|
||||||
'override' => array(
|
|
||||||
'dir' => _PS_THEME_SELECTED_DIR_.'pdf/lang/',
|
|
||||||
'file' => $this->lang_selected->iso_code.'.php'
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
'mails' => array(
|
'mails' => array(
|
||||||
'name' => $this->l('Email templates translations'),
|
'name' => $this->l('Email templates translations'),
|
||||||
'var' => '_LANGMAIL',
|
'var' => '_LANGMAIL',
|
||||||
'dir' => _PS_MAIL_DIR_.$this->lang_selected->iso_code.'/',
|
'dir' => _PS_MAIL_DIR_.$this->lang_selected->iso_code.'/',
|
||||||
'file' => 'lang.php',
|
'file' => 'lang.php'
|
||||||
'override' => array(
|
|
||||||
'dir' => _PS_THEME_SELECTED_DIR_.'mails/'.$this->lang_selected->iso_code.'/',
|
|
||||||
'file' => 'lang.php'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (defined('_PS_THEME_SELECTED_DIR_'))
|
||||||
|
{
|
||||||
|
$this->translations_informations['modules']['override'] = array('dir' => _PS_THEME_SELECTED_DIR_.'modules/', 'file' => '');
|
||||||
|
$this->translations_informations['pdf']['override'] = array('dir' => _PS_THEME_SELECTED_DIR_.'pdf/lang/', 'file' => $this->lang_selected->iso_code.'.php');
|
||||||
|
$this->translations_informations['mails']['override'] = array('dir' => _PS_THEME_SELECTED_DIR_.'mails/'.$this->lang_selected->iso_code.'/', 'file' => 'lang.php');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1204,16 +1198,14 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
foreach ($this->themes as $existing_theme)
|
foreach ($this->themes as $existing_theme)
|
||||||
if ($existing_theme->directory == $theme)
|
if ($existing_theme->directory == $theme)
|
||||||
$theme_exists = true;
|
$theme_exists = true;
|
||||||
if ($theme_exists)
|
if (!$theme_exists)
|
||||||
$this->theme_selected = Tools::safeOutput($theme);
|
|
||||||
else
|
|
||||||
throw new PrestaShopException(sprintf(Tools::displayError('Invalid theme "%s"'), $theme));
|
throw new PrestaShopException(sprintf(Tools::displayError('Invalid theme "%s"'), $theme));
|
||||||
|
$this->theme_selected = Tools::safeOutput($theme);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
$this->theme_selected = self::DEFAULT_THEME_NAME;
|
|
||||||
|
|
||||||
// Set the path of selected theme
|
// Set the path of selected theme
|
||||||
define('_PS_THEME_SELECTED_DIR_', _PS_ROOT_DIR_.'/themes/'.$this->theme_selected.'/');
|
if ($this->theme_selected)
|
||||||
|
define('_PS_THEME_SELECTED_DIR_', _PS_ROOT_DIR_.'/themes/'.$this->theme_selected.'/');
|
||||||
|
|
||||||
// Get type of translation
|
// Get type of translation
|
||||||
if (($type = Tools::getValue('type')) && !is_array($type))
|
if (($type = Tools::getValue('type')) && !is_array($type))
|
||||||
@@ -1294,7 +1286,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
// Only the PrestaShop team should write the translations into the _PS_TRANSLATIONS_DIR_
|
// Only the PrestaShop team should write the translations into the _PS_TRANSLATIONS_DIR_
|
||||||
if (($this->theme_selected == self::DEFAULT_THEME_NAME) && _PS_MODE_DEV_)
|
if (!$this->theme_selected)
|
||||||
$this->writeTranslationFile();
|
$this->writeTranslationFile();
|
||||||
else
|
else
|
||||||
$this->writeTranslationFile(true);
|
$this->writeTranslationFile(true);
|
||||||
@@ -1339,7 +1331,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
// Get files of all modules
|
// Get files of all modules
|
||||||
$arr_files = $this->getAllModuleFiles($modules, null, $this->lang_selected->iso_code, true);
|
$arr_files = $this->getAllModuleFiles($modules, null, $this->lang_selected->iso_code, true);
|
||||||
|
|
||||||
// Find and write all translation modules files
|
// Find and write all translation modules files
|
||||||
foreach ($arr_files as $value)
|
foreach ($arr_files as $value)
|
||||||
$this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir']);
|
$this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir']);
|
||||||
@@ -1409,7 +1401,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
$arr_mail_content['core_mail'] = Tools::getValue('core_mail');
|
$arr_mail_content['core_mail'] = Tools::getValue('core_mail');
|
||||||
|
|
||||||
// Get path of directory for find a good path of translation file
|
// Get path of directory for find a good path of translation file
|
||||||
if ($this->theme_selected == self::DEFAULT_THEME_NAME && _PS_MODE_DEV_)
|
if (!$this->theme_selected)
|
||||||
$arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['dir'];
|
$arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['dir'];
|
||||||
else
|
else
|
||||||
$arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['override']['dir'];
|
$arr_mail_path['core_mail'] = $this->translations_informations[$this->type_selected]['override']['dir'];
|
||||||
@@ -1420,7 +1412,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
$arr_mail_content['module_mail'] = Tools::getValue('module_mail');
|
$arr_mail_content['module_mail'] = Tools::getValue('module_mail');
|
||||||
|
|
||||||
// Get path of directory for find a good path of translation file
|
// Get path of directory for find a good path of translation file
|
||||||
if ($this->theme_selected == self::DEFAULT_THEME_NAME && _PS_MODE_DEV_)
|
if (!$this->theme_selected)
|
||||||
$arr_mail_path['module_mail'] = $this->translations_informations['modules']['dir'].'{module}/mails/'.$this->lang_selected->iso_code.'/';
|
$arr_mail_path['module_mail'] = $this->translations_informations['modules']['dir'].'{module}/mails/'.$this->lang_selected->iso_code.'/';
|
||||||
else
|
else
|
||||||
$arr_mail_path['module_mail'] = $this->translations_informations['modules']['override']['dir'].'{module}/mails/'.$this->lang_selected->iso_code.'/';
|
$arr_mail_path['module_mail'] = $this->translations_informations['modules']['override']['dir'].'{module}/mails/'.$this->lang_selected->iso_code.'/';
|
||||||
@@ -2300,7 +2292,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
if (!in_array($module_dir, self::$ignore_folder))
|
if (!in_array($module_dir, self::$ignore_folder))
|
||||||
{
|
{
|
||||||
$dir = false;
|
$dir = false;
|
||||||
if (($this->theme_selected != self::DEFAULT_THEME_NAME || !_PS_MODE_DEV_) && Tools::file_exists_cache($this->translations_informations['modules']['override']['dir'].$module_dir.'/mails/'))
|
if ($this->theme_selected && Tools::file_exists_cache($this->translations_informations['modules']['override']['dir'].$module_dir.'/mails/'))
|
||||||
$dir = $this->translations_informations['modules']['override']['dir'].$module_dir.'/';
|
$dir = $this->translations_informations['modules']['override']['dir'].$module_dir.'/';
|
||||||
elseif (Tools::file_exists_cache($this->translations_informations['modules']['dir'].$module_dir.'/mails/'))
|
elseif (Tools::file_exists_cache($this->translations_informations['modules']['dir'].$module_dir.'/mails/'))
|
||||||
$dir = $this->translations_informations['modules']['dir'].$module_dir.'/';
|
$dir = $this->translations_informations['modules']['dir'].$module_dir.'/';
|
||||||
@@ -2359,7 +2351,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
$subject_mail = $this->getSubjectMail($dir, $file, $subject_mail);
|
$subject_mail = $this->getSubjectMail($dir, $file, $subject_mail);
|
||||||
|
|
||||||
// Get path of directory for find a good path of translation file
|
// Get path of directory for find a good path of translation file
|
||||||
if (($this->theme_selected != self::DEFAULT_THEME_NAME || !_PS_MODE_DEV_) && @filemtime($this->translations_informations[$this->type_selected]['override']['dir']))
|
if ($this->theme_selected && @filemtime($this->translations_informations[$this->type_selected]['override']['dir']))
|
||||||
$i18n_dir = $this->translations_informations[$this->type_selected]['override']['dir'];
|
$i18n_dir = $this->translations_informations[$this->type_selected]['override']['dir'];
|
||||||
else
|
else
|
||||||
$i18n_dir = $this->translations_informations[$this->type_selected]['dir'];
|
$i18n_dir = $this->translations_informations[$this->type_selected]['dir'];
|
||||||
@@ -2534,28 +2526,33 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
$root_dir = $initial_root_dir;
|
$root_dir = $initial_root_dir;
|
||||||
if ($module{0} == '.')
|
if ($module{0} == '.')
|
||||||
continue;
|
continue;
|
||||||
// Get path of directory for find a good path of translation file
|
|
||||||
if ($root_dir == null)
|
// First we load the default translation file
|
||||||
{
|
|
||||||
$i18n_dir = $this->translations_informations[$this->type_selected]['override']['dir'];
|
|
||||||
if (is_dir($i18n_dir.$module))
|
|
||||||
$root_dir = $i18n_dir;
|
|
||||||
}
|
|
||||||
if ($root_dir == null)
|
if ($root_dir == null)
|
||||||
{
|
{
|
||||||
$i18n_dir = $this->translations_informations[$this->type_selected]['dir'];
|
$i18n_dir = $this->translations_informations[$this->type_selected]['dir'];
|
||||||
if (is_dir($i18n_dir.$module))
|
if (is_dir($i18n_dir.$module))
|
||||||
$root_dir = $i18n_dir;
|
$root_dir = $i18n_dir;
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dir($root_dir.$module))
|
|
||||||
{
|
|
||||||
if (Tools::file_exists_cache($root_dir.$module.'/translations/'.$lang.'.php'))
|
if (Tools::file_exists_cache($root_dir.$module.'/translations/'.$lang.'.php'))
|
||||||
$lang_file = $root_dir.$module.'/translations/'.$lang.'.php';
|
$lang_file = $root_dir.$module.'/translations/'.$lang.'.php';
|
||||||
else
|
else
|
||||||
$lang_file = $root_dir.$module.'/'.$lang.'.php';
|
$lang_file = $root_dir.$module.'/'.$lang.'.php';
|
||||||
@include($lang_file);
|
@include($lang_file);
|
||||||
|
$this->getModuleTranslations();
|
||||||
|
$this->recursiveGetModuleFiles($root_dir.$module.'/', $array_files, $module, $lang_file, $is_default);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then we load the overriden translation file
|
||||||
|
if (isset($this->translations_informations[$this->type_selected]['override']))
|
||||||
|
{
|
||||||
|
$i18n_dir = $this->translations_informations[$this->type_selected]['override']['dir'];
|
||||||
|
if (is_dir($i18n_dir.$module))
|
||||||
|
$root_dir = $i18n_dir;
|
||||||
|
if (Tools::file_exists_cache($root_dir.$module.'/translations/'.$lang.'.php'))
|
||||||
|
$lang_file = $root_dir.$module.'/translations/'.$lang.'.php';
|
||||||
|
else
|
||||||
|
$lang_file = $root_dir.$module.'/'.$lang.'.php';
|
||||||
|
@include($lang_file);
|
||||||
$this->getModuleTranslations();
|
$this->getModuleTranslations();
|
||||||
$this->recursiveGetModuleFiles($root_dir.$module.'/', $array_files, $module, $lang_file, $is_default);
|
$this->recursiveGetModuleFiles($root_dir.$module.'/', $array_files, $module, $lang_file, $is_default);
|
||||||
}
|
}
|
||||||
@@ -2641,7 +2638,7 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
$i18n_dir = $this->translations_informations[$this->type_selected]['dir'];
|
$i18n_dir = $this->translations_informations[$this->type_selected]['dir'];
|
||||||
$default_i18n_file = $i18n_dir.$this->translations_informations[$this->type_selected]['file'];
|
$default_i18n_file = $i18n_dir.$this->translations_informations[$this->type_selected]['file'];
|
||||||
|
|
||||||
if (($this->theme_selected == self::DEFAULT_THEME_NAME) && _PS_MODE_DEV_)
|
if (!$this->theme_selected)
|
||||||
$i18n_file = $default_i18n_file;
|
$i18n_file = $default_i18n_file;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user