Changeset 815 for trunk/includes/Locale.php
- Timestamp:
- Feb 22, 2015, 11:05:49 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/Locale.php
r619 r815 1 1 <?php 2 2 3 class LocaleText 3 class LocaleText 4 4 { 5 5 var $Data; … … 12 12 $this->Code = 'en'; 13 13 $this->Title = 'English'; 14 } 15 14 } 15 16 16 function Load() 17 17 { 18 18 } 19 19 20 20 function Translate($Text) 21 { 21 { 22 22 if(array_key_exists($Text, $this->Data) and ($this->Data[$Text] != '')) 23 23 return($this->Data[$Text]); 24 24 else return($Text); 25 } 25 } 26 26 } 27 27 … … 30 30 var $Texts; 31 31 var $Dir; 32 32 33 33 function __construct($System) 34 34 { … … 36 36 $this->Texts = new LocaleText(); 37 37 } 38 38 39 39 function Load($Language) 40 40 { … … 42 42 if(file_exists($FileName)) { 43 43 include_once($FileName); 44 $ClassName = 'LocaleText'.$Language; 44 $ClassName = 'LocaleText'.$Language; 45 45 $this->Texts = new $ClassName(); 46 46 } else throw new Exception('Language file '.$FileName.' not found'); 47 47 $this->Texts->Load(); 48 48 } 49 49 50 50 function AnalyzeCode($Path) 51 51 { … … 60 60 else if(file_exists($FullName)) 61 61 { 62 if(substr($FullName, -4) == '.php') 62 if(substr($FullName, -4) == '.php') 63 63 { 64 64 $Content = file_get_contents($FullName); 65 65 // Search occurence of T() function 66 66 while(strpos($Content, 'T(') !== false) 67 { 67 { 68 68 $Previous = strtolower(substr($Content, strpos($Content, 'T(') - 1, 1)); 69 69 $Content = substr($Content, strpos($Content, 'T(') + 2); … … 71 71 //echo($Ord.','); 72 72 if(!(($Ord >= ord('a')) and ($Ord <= ord('z')))) 73 { 74 // Do for non-alpha previous character 73 { 74 // Do for non-alpha previous character 75 75 $Original = substr($Content, 0, strpos($Content, ')')); 76 76 $Original2 = ''; 77 if((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'")) 77 if((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'")) 78 78 $Original2 = substr($Original, 1, -1); 79 if((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"')) 80 $Original2 = substr($Original, 1, -1); 81 if($Original2 != '') 79 if((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"')) 80 $Original2 = substr($Original, 1, -1); 81 if($Original2 != '') 82 82 { 83 83 if(!array_key_exists($Original2, $this->Texts->Data)) 84 84 $this->Texts->Data[$Original2] = ''; 85 } 85 } 86 86 } 87 } 88 } 89 } 87 } 88 } 89 } 90 90 } 91 91 } 92 92 93 93 function SaveToFile($FileName) 94 94 { … … 111 111 file_put_contents($FileName, $Content); 112 112 } 113 113 114 114 function LoadFromDatabase($Database, $LangCode) 115 115 { … … 150 150 $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '. 151 151 '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item)); 152 else $Database->insert('Locale', array('Language' => $Language['Id'], 152 else $Database->insert('Locale', array('Language' => $Language['Id'], 153 153 'Original' => $Index, 'Translated' => $Item)); 154 154 } … … 162 162 var $Codes; 163 163 var $Dir; 164 164 165 165 function __construct($System) 166 166 { 167 167 parent::__construct($System); 168 168 $this->Codes = array('en'); 169 $this->CurrentLocale = new LocaleFile($System); 170 } 171 169 $this->CurrentLocale = new LocaleFile($System); 170 } 171 172 172 function LoadAvailable() 173 173 { … … 177 177 { 178 178 if(substr($FileName, -4) == '.php') 179 { 179 { 180 180 $Code = substr($FileName, 0, -4); 181 181 $Locale = new LocaleFile($this->System); … … 183 183 $Locale->Load($Code); 184 184 $this->Available['Code'] = array('Code' => $Code, 'Title' => $Locale->Texts->Title); 185 } 185 } 186 186 } 187 187 } 188 188 189 189 function UpdateAll($Directory) 190 190 { … … 195 195 { 196 196 if(substr($FileName, -4) == '.php') 197 { 197 { 198 198 $FileLocale = new LocaleFile($this->System); 199 $FileLocale->Dir = $this->Dir; 199 $FileLocale->Dir = $this->Dir; 200 200 $FileLocale->Load(substr($FileName, 0, -4)); 201 201 202 202 // Add new 203 203 foreach($Locale->Texts->Data as $Index => $Item) … … 215 215 $this->CurrentLocale->Load($this->CurrentLocale->Texts->Code); 216 216 } 217 217 218 218 function LoadLocale($Code) 219 219 { … … 227 227 { 228 228 global $LocaleManager; 229 229 230 230 if(isset($LocaleManager)) return($LocaleManager->CurrentLocale->Texts->Translate($Text)); 231 231 else return($Text);
Note:
See TracChangeset
for help on using the changeset viewer.