Changeset 55 for trunk/Packages/Common/Locale.php
- Timestamp:
- Apr 7, 2020, 12:55:39 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Locale.php
r37 r55 20 20 function Translate($Text, $Group = '') 21 21 { 22 if (array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != ''))23 return ($this->Data[$Group][$Text]);24 else return ($Text);22 if (array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != '')) 23 return $this->Data[$Group][$Text]; 24 else return $Text; 25 25 } 26 26 … … 28 28 { 29 29 $Key = array_search($Text, $this->Data[$Group]); 30 if (($Key === FALSE) or ($this->Data[$Group][$Key] == '')) return($Text);31 else return ($Key);30 if (($Key === FALSE) or ($this->Data[$Group][$Key] == '')) return $Text; 31 else return $Key; 32 32 } 33 33 } … … 47 47 { 48 48 $FileName = $this->Dir.'/'.$Language.'.php'; 49 if (file_exists($FileName)) {49 if (file_exists($FileName)) { 50 50 include_once($FileName); 51 51 $ClassName = 'LocaleText'.$Language; … … 59 59 // Search for php files 60 60 $FileList = scandir($Path); 61 foreach ($FileList as $FileName)61 foreach ($FileList as $FileName) 62 62 { 63 63 $FullName = $Path.'/'.$FileName; 64 if (($FileName == '.') or ($FileName == '..')) ; // Skip virtual items65 else if (substr($FileName, 0, 1) == '.') ; // Skip Linux hidden files66 else if (is_dir($FullName)) $this->AnalyzeCode($FullName);67 else if (file_exists($FullName))68 { 69 if (substr($FullName, -4) == '.php')64 if (($FileName == '.') or ($FileName == '..')) ; // Skip virtual items 65 else if (substr($FileName, 0, 1) == '.') ; // Skip Linux hidden files 66 else if (is_dir($FullName)) $this->AnalyzeCode($FullName); 67 else if (file_exists($FullName)) 68 { 69 if (substr($FullName, -4) == '.php') 70 70 { 71 71 $Content = file_get_contents($FullName); 72 72 // Search occurence of T() function 73 while (strpos($Content, 'T(') !== false)73 while (strpos($Content, 'T(') !== false) 74 74 { 75 75 $Previous = strtolower(substr($Content, strpos($Content, 'T(') - 1, 1)); … … 77 77 $Ord = ord($Previous); 78 78 //echo($Ord.','); 79 if (!(($Ord >= ord('a')) and ($Ord <= ord('z'))))79 if (!(($Ord >= ord('a')) and ($Ord <= ord('z')))) 80 80 { 81 81 // Do for non-alpha previous character 82 82 $Original = substr($Content, 0, strpos($Content, ')')); 83 83 $Original2 = ''; 84 if ((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'"))84 if ((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'")) 85 85 $Original2 = substr($Original, 1, -1); 86 if ((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"'))86 if ((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"')) 87 87 $Original2 = substr($Original, 1, -1); 88 if ($Original2 != '')88 if ($Original2 != '') 89 89 { 90 if (!array_key_exists($Original2, $this->Texts->Data))90 if (!array_key_exists($Original2, $this->Texts->Data)) 91 91 $this->Texts->Data[$Original2] = ''; 92 92 } … … 109 109 ' $this->Title = \''.$this->Texts->Title.'\';'."\n". 110 110 ' $this->Data = array('."\n"; 111 foreach ($this->Texts->Data as $Index => $Item)111 foreach ($this->Texts->Data as $Index => $Item) 112 112 { 113 113 $Content .= " '".$Index."' => '".$Item."',\n"; … … 122 122 { 123 123 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); 124 if ($DbResult->num_rows > 0)124 if ($DbResult->num_rows > 0) 125 125 { 126 126 $Language = $DbResult->fetch_assoc(); 127 127 $this->Texts->Data = array(); 128 128 $DbResult = $Database->select('Locale', '`Original`, `Translated`', '`Language`='.$Language['Id']); 129 while ($DbRow = $DbResult->fetch_assoc())129 while ($DbRow = $DbResult->fetch_assoc()) 130 130 $this->Texts->Data[$DbRow['Original']] = $DbRow['Translated']; 131 131 } … … 135 135 { 136 136 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); 137 if ($DbResult->num_rows > 0)137 if ($DbResult->num_rows > 0) 138 138 { 139 139 $Language = $DbResult->fetch_assoc(); 140 140 $Database->delete('Locale', '`Language`='.$Language['Id']); 141 foreach ($this->Texts->Data as $Index => $Item)141 foreach ($this->Texts->Data as $Index => $Item) 142 142 $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '. 143 143 'VALUES('.$Language['Id'].','.$Database->quote($Index).','.$Database->quote($Item).')'); … … 148 148 { 149 149 $DbResult = $Database->select('Language', '*', '`Code`='.$Database->quote($LangCode)); 150 if ($DbResult->num_rows > 0)150 if ($DbResult->num_rows > 0) 151 151 { 152 152 $Language = $DbResult->fetch_assoc(); 153 foreach ($this->Texts->Data as $Index => $Item)153 foreach ($this->Texts->Data as $Index => $Item) 154 154 { 155 155 $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index). 156 156 ') AND (`Language`='.($Language['Id']).')'); 157 if ($DbResult->num_rows > 0)157 if ($DbResult->num_rows > 0) 158 158 $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 159 159 '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item)); … … 188 188 $this->Available = array(); 189 189 $FileList = scandir($this->Dir); 190 foreach ($FileList as $FileName)191 { 192 if (substr($FileName, -4) == '.php')190 foreach ($FileList as $FileName) 191 { 192 if (substr($FileName, -4) == '.php') 193 193 { 194 194 $Code = substr($FileName, 0, -4); … … 206 206 $Locale->AnalyzeCode($Directory); 207 207 $FileList = scandir($this->Dir); 208 foreach ($FileList as $FileName)209 { 210 if (substr($FileName, -4) == '.php')208 foreach ($FileList as $FileName) 209 { 210 if (substr($FileName, -4) == '.php') 211 211 { 212 212 $FileLocale = new LocaleFile($this->System); … … 215 215 216 216 // Add new 217 foreach ($Locale->Texts->Data as $Index => $Item)218 if (!array_key_exists($Index, $FileLocale->Texts->Data))217 foreach ($Locale->Texts->Data as $Index => $Item) 218 if (!array_key_exists($Index, $FileLocale->Texts->Data)) 219 219 $FileLocale->Texts->Data[$Index] = $Item; 220 220 // Remove old 221 foreach ($FileLocale->Texts->Data as $Index => $Item)222 if (!array_key_exists($Index, $Locale->Texts->Data))221 foreach ($FileLocale->Texts->Data as $Index => $Item) 222 if (!array_key_exists($Index, $Locale->Texts->Data)) 223 223 unset($FileLocale->Texts->Data[$Index]); 224 224 $FileLocale->UpdateToDatabase($this->System->Database, $FileLocale->Texts->Code); … … 232 232 function LoadLocale($Code) 233 233 { 234 if (array_key_exists($Code, $this->Available))234 if (array_key_exists($Code, $this->Available)) 235 235 { 236 236 $this->CurrentLocale->Dir = $this->Dir; … … 245 245 global $GlobalLocaleManager; 246 246 247 if (isset($GlobalLocaleManager)) return($GlobalLocaleManager->CurrentLocale->Texts->Translate($Text, $Group));248 else return ($Text);249 } 247 if (isset($GlobalLocaleManager)) return $GlobalLocaleManager->CurrentLocale->Texts->Translate($Text, $Group); 248 else return $Text; 249 }
Note:
See TracChangeset
for help on using the changeset viewer.