From 22392cdff2a49fe85a86d9c0b5abf5c16d46c06c Mon Sep 17 00:00:00 2001 From: Mafoo Date: Sat, 10 Jun 2017 16:14:58 +0100 Subject: [PATCH] Enhance text class (#2670) make the get routine a little more rugged by checking if the file exists not the directory it is in. throw a exception if we are asked to load a app_languages that doesn't exist don't reload the resources/app_languages if exclude_global was ommitted code styling update to match project --- resources/classes/text.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/resources/classes/text.php b/resources/classes/text.php index 353e566fdc..b555e52d0a 100644 --- a/resources/classes/text.php +++ b/resources/classes/text.php @@ -71,20 +71,26 @@ class text { else { $lang_path = getcwd(); } - if(file_exists($lang_path)) { - require $lang_path."/app_languages.php"; + if (file_exists("${lang_path}/app_languages.php")) { + if ($lang_path != 'resources' or $exclude_global) { + require "${lang_path}/app_languages.php"; + } + } + else { + throw new Exception("could not find app_languages for '$app_path'"); } //check the session language if (isset($_SESSION['domain']) and $language_code == null) { $language_code = $_SESSION['domain']['language']['code']; - } elseif ($language_code == null){ + } + elseif ($language_code == null) { $language_code = 'en-us'; } //check the language code - if(strlen($language_code) == 2) { - if(array_key_exists($language_code, $this->legacy_map)) { + if (strlen($language_code) == 2) { + if (array_key_exists($language_code, $this->legacy_map)) { $language_code = $this->legacy_map[$language_code]; } } @@ -94,7 +100,8 @@ class text { if (is_array($text)) foreach ($text as $key => $value) { if (strlen($value[$language_code]) > 0) { $text[$key] = $value[$language_code]; - } else { + } + else { //fallback to en-us $text[$key] = $value['en-us']; }