From c6bd82bf3e9fb6a494ee0713b0c7108cb415f3c2 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Tue, 21 Feb 2012 14:30:23 +0000 Subject: [PATCH] [-] BO : fix bug #PSFV-322 - Action name in custom controllers is not translated git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13502 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Translate.php | 45 +++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/classes/Translate.php b/classes/Translate.php index fb2369e5a..cc3535bf0 100644 --- a/classes/Translate.php +++ b/classes/Translate.php @@ -65,24 +65,42 @@ class TranslateCore return Translate::getModuleTranslation(Module::$classInModule[$class_name_controller], $string, $class); } } - $key = md5(str_replace('\'', '\\\'', $string)); - // retrocomp : if value is not set, try with "AdminTab" as prefix. - // @todo : change AdminTab to Helper + $key = md5(str_replace('\'', '\\\'', $string)); if (isset($_LANGADM[$class.$key])) $str = $_LANGADM[$class.$key]; - else if (isset($_LANGADM['AdminController'.$key])) - $str = $_LANGADM['AdminController'.$key]; - else if (isset($_LANGADM['Helper'.$key])) - $str = $_LANGADM['Helper'.$key]; - else if (isset($_LANGADM['AdminTab'.$key])) - $str = $_LANGADM['AdminTab'.$key]; + else + $str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM); + + $str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str; + return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str))); + } + + /** + * Return the translation for a string if it exists for the base AdminController or for helpers + * + * @static + * @param $string string to translate + * @param null $key md5 key if already calculated (optional) + * @param $lang_array global array of admin translations + * @return string translation + */ + public static function getGenericAdminTranslation($string, $key = null, $lang_array) + { + if (is_null($key)) + $key = md5(str_replace('\'', '\\\'', $string)); + + if (isset($lang_array['AdminController'.$key])) + $str = $lang_array['AdminController'.$key]; + else if (isset($lang_array['Helper'.$key])) + $str = $lang_array['Helper'.$key]; + else if (isset($lang_array['AdminTab'.$key])) + $str = $lang_array['AdminTab'.$key]; else // note in 1.5, some translations has moved from AdminXX to helper/*.tpl $str = $string; - $str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str; - return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str))); + return $str; } /** @@ -95,7 +113,7 @@ class TranslateCore */ public static function getModuleTranslation($module, $string, $source) { - global $_MODULES, $_MODULE; + global $_MODULES, $_MODULE, $_LANGADM; static $lang_cache = array(); if ($module instanceof Module) @@ -139,6 +157,9 @@ class TranslateCore $ret = stripslashes($_MODULES[$defaultKey]); elseif (isset($_MODULES[Tools::strtolower($defaultKey)])) $ret = stripslashes($_MODULES[Tools::strtolower($defaultKey)]); + // if translation was not found in module, look for it in AdminController or Helpers + elseif (!empty($_LANGADM)) + $ret = Translate::getGenericAdminTranslation($string, null, $_LANGADM); else $ret = stripslashes($string);