From 91aaa63f26ac6f0b3f90326593e837dca047dfd7 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Tue, 29 May 2012 12:50:59 +0000 Subject: [PATCH] [-] BO : #PSCFV-2591 : fix translations in bankwire module --- classes/Translate.php | 42 ++++++++++++++++++++----------- config/smartyfront.config.inc.php | 8 +----- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/classes/Translate.php b/classes/Translate.php index ff0871305..743c127fc 100644 --- a/classes/Translate.php +++ b/classes/Translate.php @@ -55,14 +55,6 @@ class TranslateCore include_once(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php'); } - if (preg_match_all('#(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])#', $string, $matches) && !is_null($sprintf)) - { - if (!is_array($sprintf)) - $sprintf = array($sprintf); - - $string = vsprintf($string, $sprintf); - } - if (isset($modules_tabs[strtolower($class)])) { $class_name_controller = $class.'controller'; @@ -83,6 +75,8 @@ class TranslateCore $str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str; $str = str_replace('"', '"', $str); + $str = Translate::checkAndReplaceArgs($str, $sprintf); + return ($addslashes ? addslashes($str) : stripslashes($str)); } @@ -172,18 +166,15 @@ class TranslateCore $key = md5(str_replace('\'', '\\\'', $string)); $cache_key = $name.'|'.$string.'|'.$source; + if (!isset($lang_cache[$cache_key])) { - if (preg_match_all('#(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])#', $string, $matches) && !is_null($sprintf)) - { - if (!is_array($sprintf)) - $sprintf = array($sprintf); - - $string = vsprintf($string, $sprintf); - } if ($_MODULES == null) + { + $string = Translate::checkAndReplaceArgs($string, $sprintf); return str_replace('"', '"', $string); + } $current_key = strtolower('<{'.$name.'}'._THEME_NAME_.'>'.$source).'_'.$key; $default_key = strtolower('<{'.$name.'}prestashop>'.$source).'_'.$key; @@ -198,6 +189,8 @@ class TranslateCore else $ret = stripslashes($string); + $ret = Translate::checkAndReplaceArgs($ret, $sprintf); + $lang_cache[$cache_key] = str_replace('"', '"', $ret); } return $lang_cache[$cache_key]; @@ -235,5 +228,24 @@ class TranslateCore return $str; } + + /** + * Check if string use a specif syntax for sprintf and replace arguments if use it + * + * @param $string + * @param $args + * @return string + */ + public static function checkAndReplaceArgs($string, $args) + { + if (preg_match_all('#(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])#', $string, $matches) && !is_null($args)) + { + if (!is_array($args)) + $args = array($args); + + return vsprintf($string, $args); + } + return $string; + } } diff --git a/config/smartyfront.config.inc.php b/config/smartyfront.config.inc.php index 2faf094fd..c2f8f9e9d 100644 --- a/config/smartyfront.config.inc.php +++ b/config/smartyfront.config.inc.php @@ -61,13 +61,7 @@ function smartyTranslate($params, &$smarty) if ($msg != $params['s']) $msg = $params['js'] ? addslashes($msg) : stripslashes($msg); - if (preg_match_all('#(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])#', $msg, $matches) && !is_null($params['sprintf'])) - { - if (!is_array($params['sprintf'])) - $params['sprintf'] = array($params['sprintf']); - - $msg = vsprintf($msg, $params['sprintf']); - } + $msg = Translate::checkAndReplaceArgs($msg, $params['sprintf']); return $params['js'] ? $msg : Tools::htmlentitiesUTF8($msg); }