Ticket #543: 543-jLocale-utf8-entities-fix-and-other-improvements.diff
| File 543-jLocale-utf8-entities-fix-and-other-improvements.diff, 8.7 kB (added by Julien, 4 months ago) |
|---|
-
trunk/lib/jelix/core/jLocale.class.php
old new 4 4 * @subpackage core 5 5 * @author Laurent Jouanneau 6 6 * @author Gerald Croes 7 * @contributor 7 * @contributor Julien Issler 8 8 * @copyright 2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau 9 * @copyright 2008 Julien Issler 9 10 * Some parts of this file are took from Copix Framework v2.3dev20050901, CopixI18N.class.php, http://www.copix.org. 10 11 * copyrighted by CopixTeam and released under GNU Lesser General Public Licence. 11 12 * initial authors : Gerald Croes, Laurent Jouanneau. … … 106 107 /** 107 108 * loads a given resource from its path. 108 109 */ 109 protected function _loadResources ($fi chier, $charset){110 protected function _loadResources ($file, $charset){ 110 111 111 if (($f = @fopen ($fichier, 'r')) !== false) { 112 $multiline=false; 113 $linenumber=0; 114 $key=''; 115 while (!feof($f)) { 116 if($line=fgets($f)){ 117 $linenumber++; 118 $line=rtrim($line); 119 if($multiline){ 120 if(preg_match("/^\s*(.*)\s*(\\\\?)$/U", $line, $match)){ 121 $sp = preg_split('/(?<!\\\\)\#/', $match[1], -1 ,PREG_SPLIT_NO_EMPTY); 122 $multiline= ($match[2] =="\\"); 123 $this->_strings[$charset][$key].=' '.trim(str_replace('\#','#',$sp[0])); 124 }else{ 125 throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,210); 126 } 127 }elseif(preg_match("/^\s*(.+)\s*=\s*(.*)\s*(\\\\?)$/U",$line, $match)){ 128 // on a bien un cle=valeur 129 $key=$match[1]; 130 $multiline= ($match[3] =="\\"); 131 $sp = preg_split('/(?<!\\\\)\#/', $match[2], -1 ,PREG_SPLIT_NO_EMPTY); 132 if(count($sp)){ 133 $value=trim(str_replace('\#','#',$sp[0])); 134 if($value == '\w'){ 135 $value = ' '; 136 } 137 }else{ 138 $value=''; 139 } 112 if(!file_exists($file)) 113 throw new Exception('Cannot load the resource '.$file,212); 140 114 141 $this->_strings[$charset][$key] =$value; 115 $new_line = true; 116 foreach(file($file) as $linenumber=>$line){ 117 if(strpos($line,'#')===0) 118 continue; 142 119 143 }elseif(preg_match("/^\s*(\#.*)?$/",$line, $match)){ 144 // ok, juste un commentaire 145 }else { 146 throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,211); 147 } 148 } 120 if($new_line){ 121 if(!preg_match('#^([^=]+)=(.+)(\\\{1,2})?$#U',$line,$matches)) 122 throw new Exception('Syntax error in localization file "'.$file.'" at line '.($linenumber+1),210); 123 124 $key = trim($matches[1]); 125 $this->_strings[$charset][$key] = ''; 126 $string_index = 2; 127 $eol_index = 3; 149 128 } 150 fclose ($f); 151 }else{ 152 throw new Exception('Cannot load the resource '.$fichier,212); 129 else{ 130 if(!preg_match('#^(.+)(\\\{1,2})?$#U',$line,$matches)) 131 throw new Exception('Syntax error in localization file "'.$file.'" at line '.($linenumber+1),210); 132 133 $string_index = 1; 134 $eol_index = 2; 135 } 136 137 138 $string = html_entity_decode(ltrim($matches[$string_index]),ENT_COMPAT,$charset); 139 $new_line = true; 140 if(isset($matches[$eol_index])){ 141 $new_line = false; 142 if(strlen($matches[$eol_index]) == 2) 143 $string .= "\n"; 144 else 145 $string .= ' '; 146 } 147 $this->_strings[$charset][$key] .= $string; 148 153 149 } 154 150 } 155 151 } -
branches/1.0.x/lib/jelix/core/jLocale.class.php
old new 4 4 * @subpackage core 5 5 * @author Laurent Jouanneau 6 6 * @author Gerald Croes 7 * @contributor 7 * @contributor Julien Issler 8 8 * @copyright 2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau 9 * @copyright 2008 Julien Issler 9 10 * Some parts of this file are took from Copix Framework v2.3dev20050901, CopixI18N.class.php, http://www.copix.org. 10 11 * copyrighted by CopixTeam and released under GNU Lesser General Public Licence. 11 12 * initial authors : Gerald Croes, Laurent Jouanneau. … … 106 107 /** 107 108 * loads a given resource from its path. 108 109 */ 109 protected function _loadResources ($fi chier, $charset){110 protected function _loadResources ($file, $charset){ 110 111 111 if (($f = @fopen ($fichier, 'r')) !== false) { 112 $multiline=false; 113 $linenumber=0; 114 $key=''; 115 while (!feof($f)) { 116 if($line=fgets($f)){ 117 $linenumber++; 118 $line=rtrim($line); 119 if($multiline){ 120 if(preg_match("/^\s*(.*)\s*(\\\\?)$/U", $line, $match)){ 121 $sp = preg_split('/(?<!\\\\)\#/', $match[1], -1 ,PREG_SPLIT_NO_EMPTY); 122 $multiline= ($match[2] =="\\"); 123 $this->_strings[$charset][$key].=' '.trim(str_replace('\#','#',$sp[0])); 124 }else{ 125 throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,210); 126 } 127 }elseif(preg_match("/^\s*(.+)\s*=\s*(.*)\s*(\\\\?)$/U",$line, $match)){ 128 // on a bien un cle=valeur 129 $key=$match[1]; 130 $multiline= ($match[3] =="\\"); 131 $sp = preg_split('/(?<!\\\\)\#/', $match[2], -1 ,PREG_SPLIT_NO_EMPTY); 132 if(count($sp)){ 133 $value=trim(str_replace('\#','#',$sp[0])); 134 if($value == '\w'){ 135 $value = ' '; 136 } 137 }else{ 138 $value=''; 139 } 112 if(!file_exists($file)) 113 throw new Exception('Cannot load the resource '.$file,212); 140 114 141 $this->_strings[$charset][$key] =$value; 115 $new_line = true; 116 foreach(file($file) as $linenumber=>$line){ 117 if(strpos($line,'#')===0) 118 continue; 142 119 143 }elseif(preg_match("/^\s*(\#.*)?$/",$line, $match)){ 144 // ok, juste un commentaire 145 }else { 146 throw new Exception('Syntaxe error in file properties '.$fichier.' line '.$linenumber,211); 147 } 148 } 120 if($new_line){ 121 if(!preg_match('#^([^=]+)=(.+)(\\\{1,2})?$#U',$line,$matches)) 122 throw new Exception('Syntax error in localization file "'.$file.'" at line '.($linenumber+1),210); 123 124 $key = trim($matches[1]); 125 $this->_strings[$charset][$key] = ''; 126 $string_index = 2; 127 $eol_index = 3; 149 128 } 150 fclose ($f); 151 }else{ 152 throw new Exception('Cannot load the resource '.$fichier,212); 129 else{ 130 if(!preg_match('#^(.+)(\\\{1,2})?$#U',$line,$matches)) 131 throw new Exception('Syntax error in localization file "'.$file.'" at line '.($linenumber+1),210); 132 133 $string_index = 1; 134 $eol_index = 2; 135 } 136 137 138 $string = html_entity_decode(ltrim($matches[$string_index]),ENT_COMPAT,$charset); 139 $new_line = true; 140 if(isset($matches[$eol_index])){ 141 $new_line = false; 142 if(strlen($matches[$eol_index]) == 2) 143 $string .= "\n"; 144 else 145 $string .= ' '; 146 } 147 $this->_strings[$charset][$key] .= $string; 148 153 149 } 154 150 } 155 151 }
