Kaynağa Gözat

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
Mafoo 8 yıl önce
ebeveyn
işleme
ef510d9817
1 değiştirilmiş dosya ile 13 ekleme ve 6 silme
  1. 13 6
      resources/classes/text.php

+ 13 - 6
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'];
 					}