Ticket #543: 543-beta.diff

File 543-beta.diff, 2.2 kB (added by Julien, 4 months ago)

beta patch, need some more test, but if you have comments....

  • trunk/lib/jelix/core/jLocale.class.php

    old new  
    106106    /** 
    107107    * loads a given resource from its path. 
    108108    */ 
    109     protected function _loadResources ($fichier, $charset){ 
     109    protected function _loadResources ($file, $charset){ 
    110110 
     111        if(!file_exists($file)) 
     112            throw new Exception('Cannot load the resource '.$file,212); 
     113 
     114        $new_line = true; 
     115        foreach(explode("\n",file_get_contents($file)) as $linenumber=>$line){ 
     116            if(strpos($line,'#')===0) 
     117                continue; 
     118 
     119            if($new_line){ 
     120                if(!preg_match('#^([^=]+)=(.+)(\\\{1,2})?$#U',$line,$matches)) 
     121                    throw new Exception('Syntax error in localization file "'.$file.'" at line '.($linenumber+1),210); 
     122 
     123                $key = trim($matches[1]); 
     124                $this->_strings[$charset][$key] = ''; 
     125                $string_index = 2; 
     126                $eol_index = 3; 
     127            } 
     128            else{ 
     129                if(!preg_match('#^(.+)(\\\{1,2})?$#U',$line,$matches)) 
     130                    throw new Exception('Syntax error in localization file "'.$file.'" at line '.($linenumber+1),210); 
     131                 
     132                $string_index = 1; 
     133                $eol_index = 2; 
     134            } 
     135             
     136            
     137            $string = html_entity_decode(ltrim($matches[$string_index]),ENT_COMPAT,$charset); 
     138            $new_line = true; 
     139            if(isset($matches[$eol_index])){ 
     140                $new_line = false;                 
     141                if(strlen($matches[$eol_index]) == 2) 
     142                    $string .= "\n"; 
     143                else 
     144                    $string .= ' '; 
     145            } 
     146            $this->_strings[$charset][$key] .= $string;          
     147             
     148        } 
     149        /* 
    111150        if (($f = @fopen ($fichier, 'r')) !== false) { 
    112151            $multiline=false; 
    113152            $linenumber=0; 
     
    151190        }else{ 
    152191            throw new Exception('Cannot load the resource '.$fichier,212); 
    153192        } 
     193        */ 
    154194    } 
    155195} 
    156196 
Download in other formats: Original Format