Changeset 888 for trunk/Packages/Common/Locale.php
- Timestamp:
- Dec 27, 2022, 7:50:23 PM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Locale.php
r884 r888 3 3 class LocaleText 4 4 { 5 var$Data;6 var$Code;7 var$Title;5 public array $Data; 6 public string $Code; 7 public string $Title; 8 8 9 9 function __construct() … … 14 14 } 15 15 16 function Load() 17 { 18 } 19 20 function Translate( $Text, $Group = '')16 function Load(): void 17 { 18 } 19 20 function Translate(string $Text, string $Group = ''): string 21 21 { 22 22 if (array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != '')) … … 25 25 } 26 26 27 function TranslateReverse( $Text, $Group = '')27 function TranslateReverse(string $Text, string $Group = ''): string 28 28 { 29 29 $Key = array_search($Text, $this->Data[$Group]); … … 35 35 class LocaleFile extends Model 36 36 { 37 var$Texts;38 var$Dir;37 public LocaleText $Texts; 38 public string $Dir; 39 39 40 40 function __construct(System $System) … … 44 44 } 45 45 46 function Load( $Language)46 function Load(string $Language): void 47 47 { 48 48 $FileName = $this->Dir.'/'.$Language.'.php'; … … 55 55 } 56 56 57 function AnalyzeCode( $Path)57 function AnalyzeCode(string $Path): void 58 58 { 59 59 // Search for php files … … 75 75 $Previous = strtolower(substr($Content, strpos($Content, 'T(') - 1, 1)); 76 76 $Content = substr($Content, strpos($Content, 'T(') + 2); 77 $Ord = ord($Previous); 78 //echo($Ord.','); 77 $Ord = ord($Previous); 79 78 if (!(($Ord >= ord('a')) and ($Ord <= ord('z')))) 80 79 { … … 98 97 } 99 98 100 function SaveToFile( $FileName)99 function SaveToFile(string $FileName): void 101 100 { 102 101 $Content = '<?php'."\n". … … 119 118 } 120 119 121 function LoadFromDatabase( $Database, $LangCode)120 function LoadFromDatabase(Database $Database, string $LangCode): void 122 121 { 123 122 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); … … 132 131 } 133 132 134 function SaveToDatabase( Database $Database, $LangCode)135 { 136 $DbResult = $ Database->select('Language', '*', 'Code='.$Database->quote($LangCode));133 function SaveToDatabase(string $LangCode): void 134 { 135 $DbResult = $this->Database->select('Language', '*', 'Code='.$this->Database->quote($LangCode)); 137 136 if ($DbResult->num_rows > 0) 138 137 { 139 138 $Language = $DbResult->fetch_assoc(); 140 $ Database->delete('Locale', '`Language`='.$Language['Id']);139 $this->Database->delete('Locale', '`Language`='.$Language['Id']); 141 140 foreach ($this->Texts->Data as $Index => $Item) 142 $ Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.143 'VALUES('.$Language['Id'].','.$ Database->quote($Index).','.$Database->quote($Item).')');144 } 145 } 146 147 function UpdateToDatabase( Database $Database, $LangCode)148 { 149 $DbResult = $ Database->select('Language', '*', '`Code`='.$Database->quote($LangCode));141 $this->Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '. 142 'VALUES('.$Language['Id'].','.$this->Database->quote($Index).','.$this->Database->quote($Item).')'); 143 } 144 } 145 146 function UpdateToDatabase(string $LangCode): void 147 { 148 $DbResult = $this->Database->select('Language', '*', '`Code`='.$this->Database->quote($LangCode)); 150 149 if ($DbResult->num_rows > 0) 151 150 { … … 153 152 foreach ($this->Texts->Data as $Index => $Item) 154 153 { 155 if (is_array($Item)) continue; 156 $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index). 154 $DbResult = $this->Database->select('Locale', '*', '(`Original` ='.$this->Database->quote($Index). 157 155 ') AND (`Language`='.($Language['Id']).')'); 158 156 if ($DbResult->num_rows > 0) 159 { 160 $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 161 '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item)); 162 } else 163 { 164 $Database->insert('Locale', array('Language' => $Language['Id'], 165 'Original' => $Index, 'Translated' => $Item, 'Fuzzy' => 0)); 166 } 157 $this->Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 158 '(`Original` ='.$this->Database->quote($Index).')', array('Translated' => $Item)); 159 else $this->Database->insert('Locale', array('Language' => $Language['Id'], 160 'Original' => $Index, 'Translated' => $Item)); 167 161 } 168 162 } … … 172 166 class LocaleManager extends Model 173 167 { 174 var$CurrentLocale;175 var$Codes;176 var$Dir;177 var$LangCode;178 var$DefaultLangCode;179 var$Available;168 public LocaleFile $CurrentLocale; 169 public array $Codes; 170 public string $Dir; 171 public string $LangCode; 172 public string $DefaultLangCode; 173 public array $Available; 180 174 181 175 function __construct(System $System) … … 187 181 $this->DefaultLangCode = 'en'; 188 182 $this->Available = array(); 189 } 190 191 function LoadAvailable() 183 $this->Dir = ''; 184 } 185 186 function LoadAvailable(): void 192 187 { 193 188 $this->Available = array(); … … 206 201 } 207 202 208 function UpdateAll( $Directory)203 function UpdateAll(string $Directory): void 209 204 { 210 205 $Locale = new LocaleFile($this->System); … … 227 222 if (!array_key_exists($Index, $Locale->Texts->Data)) 228 223 unset($FileLocale->Texts->Data[$Index]); 229 $FileLocale->UpdateToDatabase($ this->System->Database, $FileLocale->Texts->Code);224 $FileLocale->UpdateToDatabase($FileLocale->Texts->Code); 230 225 $FileName = $this->Dir.'/'.$FileLocale->Texts->Code.'.php'; 231 226 $FileLocale->SaveToFile($FileName); … … 235 230 } 236 231 237 function LoadLocale( $Code)232 function LoadLocale(string $Code): void 238 233 { 239 234 if (array_key_exists($Code, $this->Available)) … … 246 241 247 242 // Short named global translation function 248 function T( $Text, $Group = '')243 function T(string $Text, string $Group = ''): string 249 244 { 250 245 global $GlobalLocaleManager;
Note:
See TracChangeset
for help on using the changeset viewer.