Changeset 95 for trunk/Packages/Common/Locale.php
- Timestamp:
- Dec 6, 2021, 11:33:48 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Locale.php
r92 r95 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 … … 98 98 } 99 99 100 function SaveToFile( $FileName)100 function SaveToFile(string $FileName): void 101 101 { 102 102 $Content = '<?php'."\n". … … 119 119 } 120 120 121 function LoadFromDatabase( $Database, $LangCode)121 function LoadFromDatabase(Database $Database, string $LangCode): void 122 122 { 123 123 $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode)); … … 132 132 } 133 133 134 function SaveToDatabase( Database $Database, $LangCode)135 { 136 $DbResult = $ Database->select('Language', '*', 'Code='.$Database->quote($LangCode));134 function SaveToDatabase(string $LangCode): void 135 { 136 $DbResult = $this->Database->select('Language', '*', 'Code='.$this->Database->quote($LangCode)); 137 137 if ($DbResult->num_rows > 0) 138 138 { 139 139 $Language = $DbResult->fetch_assoc(); 140 $ Database->delete('Locale', '`Language`='.$Language['Id']);140 $this->Database->delete('Locale', '`Language`='.$Language['Id']); 141 141 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));142 $this->Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '. 143 'VALUES('.$Language['Id'].','.$this->Database->quote($Index).','.$this->Database->quote($Item).')'); 144 } 145 } 146 147 function UpdateToDatabase(string $LangCode): void 148 { 149 $DbResult = $this->Database->select('Language', '*', '`Code`='.$this->Database->quote($LangCode)); 150 150 if ($DbResult->num_rows > 0) 151 151 { … … 153 153 foreach ($this->Texts->Data as $Index => $Item) 154 154 { 155 $DbResult = $ Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index).155 $DbResult = $this->Database->select('Locale', '*', '(`Original` ='.$this->Database->quote($Index). 156 156 ') AND (`Language`='.($Language['Id']).')'); 157 157 if ($DbResult->num_rows > 0) 158 $ Database->update('Locale', '(`Language`='.($Language['Id']).') AND '.159 '(`Original` ='.$ Database->quote($Index).')', array('Translated' => $Item));160 else $ Database->insert('Locale', array('Language' => $Language['Id'],158 $this->Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 159 '(`Original` ='.$this->Database->quote($Index).')', array('Translated' => $Item)); 160 else $this->Database->insert('Locale', array('Language' => $Language['Id'], 161 161 'Original' => $Index, 'Translated' => $Item)); 162 162 } … … 167 167 class LocaleManager extends Model 168 168 { 169 var$CurrentLocale;170 var$Codes;171 var$Dir;172 var$LangCode;173 var$DefaultLangCode;174 var$Available;169 public LocaleFile $CurrentLocale; 170 public array $Codes; 171 public string $Dir; 172 public string $LangCode; 173 public string $DefaultLangCode; 174 public array $Available; 175 175 176 176 function __construct(System $System) … … 182 182 $this->DefaultLangCode = 'en'; 183 183 $this->Available = array(); 184 } 185 186 function LoadAvailable() 184 $this->Dir = ''; 185 } 186 187 function LoadAvailable(): void 187 188 { 188 189 $this->Available = array(); … … 201 202 } 202 203 203 function UpdateAll( $Directory)204 function UpdateAll(string $Directory): void 204 205 { 205 206 $Locale = new LocaleFile($this->System); … … 222 223 if (!array_key_exists($Index, $Locale->Texts->Data)) 223 224 unset($FileLocale->Texts->Data[$Index]); 224 $FileLocale->UpdateToDatabase($ this->System->Database, $FileLocale->Texts->Code);225 $FileLocale->UpdateToDatabase($FileLocale->Texts->Code); 225 226 $FileName = $this->Dir.'/'.$FileLocale->Texts->Code.'.php'; 226 227 $FileLocale->SaveToFile($FileName); … … 230 231 } 231 232 232 function LoadLocale( $Code)233 function LoadLocale(string $Code): void 233 234 { 234 235 if (array_key_exists($Code, $this->Available)) … … 241 242 242 243 // Short named global translation function 243 function T( $Text, $Group = '')244 function T(string $Text, string $Group = ''): string 244 245 { 245 246 global $GlobalLocaleManager;
Note:
See TracChangeset
for help on using the changeset viewer.