Exemple #1
0
 /**
  * Get a translation for an admin controller
  *
  * @param $string
  * @param string $class
  * @param bool $addslashes
  * @param bool $htmlentities
  * @return string
  */
 public static function getAdminTranslation($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true, $sprintf = null)
 {
     static $modules_tabs = null;
     // @todo remove global keyword in translations files and use static
     global $_LANGADM;
     if ($modules_tabs === null) {
         $modules_tabs = Tab::getModuleTabList();
     }
     if ($_LANGADM == null) {
         $iso = Context::getContext()->language->iso_code;
         include_once _PS_TRANSLATIONS_DIR_ . $iso . '/admin.php';
     }
     if (isset($modules_tabs[strtolower($class)])) {
         $class_name_controller = $class . 'controller';
         // if the class is extended by a module, use modules/[module_name]/xx.php lang file
         if (class_exists($class_name_controller) && Module::getModuleNameFromClass($class_name_controller)) {
             $string = str_replace('\'', '\\\'', $string);
             return Translate::getModuleTranslation(Module::$classInModule[$class_name_controller], $string, $class_name_controller);
         }
     }
     $key = md5(str_replace('\'', '\\\'', $string));
     if (isset($_LANGADM[$class . $key])) {
         $str = $_LANGADM[$class . $key];
     } else {
         $str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
     }
     if ($htmlentities) {
         $str = htmlentities($str, ENT_QUOTES, 'utf-8');
     }
     $str = str_replace('"', '"', $str);
     if ($sprintf !== null) {
         $str = Translate::checkAndReplaceArgs($str, $sprintf);
     }
     return $addslashes ? addslashes($str) : stripslashes($str);
 }