From 4eaca1907fd3314cd82bd19fe5dd0f16576b2225 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 29 Apr 2025 16:38:13 +0530 Subject: [PATCH] Update the admin translations load process, added static variables to manage the translations load process --- classes/Translate.php | 18 +++++++++--------- .../admin/AdminTranslationsController.php | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/classes/Translate.php b/classes/Translate.php index 5401aad78..be0672e13 100644 --- a/classes/Translate.php +++ b/classes/Translate.php @@ -30,6 +30,8 @@ class TranslateCore { public static $ignore_folder = array('.', '..', '.svn', '.git', '.htaccess', 'index.php'); + public static $langAdmLoaded = false; + public static $_LANGADM = array(); /** * Get a translation for an admin controller @@ -43,21 +45,19 @@ class TranslateCore 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) { + if (!self::$langAdmLoaded) { $iso = Context::getContext()->language->iso_code; if (empty($iso)) { $iso = Language::getIsoById((int)Configuration::get('PS_LANG_DEFAULT')); } if (file_exists(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php')) { - include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php'); + self::$langAdmLoaded = true; + include_once(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php'); + self::$_LANGADM = $GLOBALS['_LANGADM']; } } @@ -71,10 +71,10 @@ class TranslateCore $string = preg_replace("/\\\*'/", "\'", $string); $key = md5($string); - if (isset($_LANGADM[$class.$key])) { - $str = $_LANGADM[$class.$key]; + if (isset(self::$_LANGADM[$class.$key])) { + $str = self::$_LANGADM[$class.$key]; } else { - $str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM); + $str = Translate::getGenericAdminTranslation($string, $key, self::$_LANGADM); } if ($htmlentities) { diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index 350fcceeb..6ccc5713c 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -1966,7 +1966,6 @@ class AdminTranslationsControllerCore extends AdminController } - unset($GLOBALS[$name_var]); // count will contain the number of expressions of the page $count = 0; foreach ($tabs_array as $array) {