Changeset 608 for trunk/includes/Locale.php
- Timestamp:
- Nov 26, 2013, 10:12:48 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/Locale.php
r603 r608 4 4 { 5 5 var $Data; 6 var $Code; 6 7 7 8 function __construct() 8 9 { 9 10 $this->Data = array(); 11 $this->Code = 'en'; 10 12 } 11 13 … … 15 17 } 16 18 17 class Locale 19 class Locale extends Model 18 20 { 19 21 var $Texts; … … 42 44 $this->Texts->Load(); 43 45 } 46 47 function AnalyzeCode($Path) 48 { 49 // Search for php files 50 $FileList = scandir($Path); 51 foreach($FileList as $FileName) 52 { 53 $FullName = $Path.'/'.$FileName; 54 if(($FileName == '.') or ($FileName == '..')) ; // Skip virtual items 55 else if(substr($FileName, 0, 1) == '.') ; // Skip Linux hidden files 56 else if(is_dir($FullName)) $this->AnalyzeCode($FullName); 57 else if(file_exists($FullName)) 58 { 59 if(substr($FullName, -4) == '.php') 60 { 61 $Content = file_get_contents($FullName); 62 // Search occurence of T() function 63 while(strpos($Content, 'T(') !== false) 64 { 65 $Previous = strtolower(substr($Content, strpos($Content, 'T(') - 1, 1)); 66 $Content = substr($Content, strpos($Content, 'T(') + 2); 67 $Ord = ord($Previous); 68 //echo($Ord.','); 69 if(!(($Ord >= ord('a')) and ($Ord <= ord('z')))) 70 { 71 // Do for non-alpha previous character 72 $Original = substr($Content, 0, strpos($Content, ')')); 73 $Original2 = ''; 74 if((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'")) 75 $Original2 = substr($Original, 1, -1); 76 if((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"')) 77 $Original2 = substr($Original, 1, -1); 78 if($Original2 != '') 79 { 80 if(!array_key_exists($Original2, $this->Texts->Data)) 81 $this->Texts->Data[$Original2] = ''; 82 } 83 } 84 } 85 } 86 } 87 } 88 } 89 90 function SaveToFile($FileName) 91 { 92 $Content = '<?php'."\n". 93 ''."\n". 94 'class LocaleText'.$this->Texts->Code.' extends LocaleText'."\n". 95 '{'."\n". 96 ' function Load()'."\n". 97 ' {'."\n". 98 ' $this->Code = \'cs\';'."\n". 99 ' $this->Data = array('."\n"; 100 foreach($this->Texts->Data as $Index => $Item) 101 { 102 $Content .= " '".$Index."' => '".$Item."',\n"; 103 } 104 $Content .= ' );'."\n". 105 ' }'."\n". 106 '}'."\n"; 107 file_put_contents($FileName, $Content); 108 } 109 110 function LoadFromDatabase($Database, $LanguageId) 111 { 112 $this->Texts->Data = array(); 113 $DbResult = $Database->select('Locale', '`Original`, `Translated`', '`Language`='.$LanguageId * 1); 114 while($DbRow = $DbResult->fetch_assoc()) 115 $this->Texts->Data[$DbRow['Original']] = $DbRow['Translated']; 116 } 117 118 function SaveToDatabase(Database $Database, $LanguageId) 119 { 120 $Database->delete('Locale', '`Language`='.$LanguageId * 1); 121 foreach($this->Texts->Data as $Index => $Item) 122 $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '. 123 'VALUES('.$LanguageId.','.$Database->quote($Index).','.$Database->quote($Item).')'); 124 } 125 126 function UpdateToDatabase(Database $Database, $LanguageId) 127 { 128 foreach($this->Texts->Data as $Index => $Item) 129 { 130 $DbResult = $Database->select('Locale', '*', '`Original` ='.$Database->quote($Index)); 131 if($DbResult->num_rows > 0) 132 $Database->update('Locale', '(`Language`='.($LanguageId * 1).') AND '. 133 '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item)); 134 else $Database->insert('Locale', array('Language' => $LanguageId * 1, 135 'Original' => $Index, 'Translated' => $Item)); 136 } 137 } 44 138 } 45 139
Note:
See TracChangeset
for help on using the changeset viewer.