Ticket #95: 95-jLocale-with-no-country-code.2.diff

File 95-jLocale-with-no-country-code.2.diff, 12.1 kB (added by Julien, 8 months ago)

enfin le bon patch ? ;)

  • trunk/testapp/modules/jelix_tests/tests/core.jlocale.html_cli.php

    old new  
    127127 
    128128        $this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale')); 
    129129        // no test2.properties file for fr_CA, so we should have the fr_FR one 
    130         //$this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale', null, 'fr_CA')); 
     130        $this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale', null, 'fr_CA')); 
    131131        // no test3.properties file for fr_CA and fr_FR, so we should have the en_EN one 
    132132        //$GLOBALS['gJConfig']->locale = 'en_EN'; 
    133133        //$this->assertEqual('this is an en_EN sentence test3',jLocale::get('tests3.first.locale', null, 'fr_CA')); 
  • trunk/lib/jelix/core/jSelector.class.php

    old new  
    352352    * @since 1.0b2 
    353353    */ 
    354354    public $subpath =''; 
    355     /**  
     355    /** 
    356356    * the class name specified in the selector 
    357357    * @since 1.0b2 
    358358    */ 
     
    391391        global $gJConfig; 
    392392        if (!isset($gJConfig->_modulesPathList[$this->module])) { 
    393393            throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    394         }  
     394        } 
    395395        $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix; 
    396396 
    397397        if (!file_exists($this->_path) || strpos($this->subpath,'..') !== false ) { // second test for security issues 
     
    412412} 
    413413 
    414414/** 
    415  * selector for interface  
     415 * selector for interface 
    416416 * 
    417417 * interface is stored in interfacename.iface.php file in the classes/ module directory 
    418418 * or one of its subdirectory. 
     
    428428} 
    429429 
    430430/** 
    431  * selector for interface  
     431 * selector for interface 
    432432 * @package    jelix 
    433433 * @subpackage core_selector 
    434434 * @since 1.0b2 
    435  * @deprecated  
     435 * @deprecated 
    436436 */ 
    437437class jSelectorInterface extends jSelectorIface {} 
    438438 
     
    469469        } 
    470470        $this->locale = $locale; 
    471471        $this->charset = $charset; 
    472         $this->_dirname =  'locales/' .$locale.'/'; 
    473472        $this->_suffix = '.'.$charset.'.properties'; 
    474         $this->_cacheSuffix = '.'.$locale.'.'.$charset.'.php'; 
    475473        $this->_compilerPath=JELIX_LIB_CORE_PATH.'jLocalesCompiler.class.php'; 
    476474 
    477475#if ENABLE_PHP_JELIX 
     
    505503            throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    506504        } 
    507505 
    508         // on regarde si la locale a été redéfini 
    509         $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/'.$this->_dirname.$this->resource.$this->_suffix; 
    510         if (is_readable ($overloadedPath)){ 
    511             $this->_path = $overloadedPath; 
    512             $this->_where = 'overloaded/'; 
    513             return; 
    514         } 
    515         // et sinon, on regarde si la locale existe dans le module en question 
    516         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix; 
     506        $locales = array($this->locale); 
     507        $lang = substr($this->locale,0,2); 
     508        $generic_locale = $lang.'_'.strtoupper($lang); 
     509        if($this->locale !== $generic_locale) 
     510            $locales[] = $generic_locale; 
    517511 
    518         if (!is_readable ($this->_path)){ 
    519             // to avoid infinite loop in a specific lang or charset, we should check if we don't 
    520             // try to retrieve the same message as the one we use for the exception below, 
    521             // and if it is this message, it means that the error message doesn't exist  
    522             // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset 
    523             if($this->toString() == 'jelix~errors.selector.invalid.target'){ 
    524                 $l = 'en_EN'; 
    525                 $c = 'UTF-8'
     512        foreach($locales as $locale){ 
     513            // check if the locale has been overloaded 
     514            $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/locales/'.$locale.'/'.$this->resource.$this->_suffix; 
     515            if (is_readable ($overloadedPath)){ 
     516                $this->_path = $overloadedPath; 
     517                $this->_where = 'overloaded/'; 
     518                $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php'; 
     519                return
    526520            } 
    527             else{ 
    528                 $l = null; 
    529                 $c = null; 
     521            // else check for the original locale file 
     522            $path = $gJConfig->_modulesPathList[$this->module].'/locales/'.$locale.'/'.$this->resource.$this->_suffix; 
     523            if (is_readable ($path)){ 
     524                $this->_where = 'modules/'; 
     525                $this->_path = $path; 
     526                $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php'; 
     527                return; 
    530528            } 
    531             throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); 
    532529        } 
    533         $this->_where = 'modules/'; 
     530 
     531        // to avoid infinite loop in a specific lang or charset, we should check if we don't 
     532        // try to retrieve the same message as the one we use for the exception below, 
     533        // and if it is this message, it means that the error message doesn't exist 
     534        // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset 
     535        if($this->toString() == 'jelix~errors.selector.invalid.target'){ 
     536            $l = 'en_EN'; 
     537            $c = 'UTF-8'; 
     538        } 
     539        else{ 
     540            $l = null; 
     541            $c = null; 
     542        } 
     543        throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); 
    534544    } 
    535545 
    536546    protected function _createCachePath(){ 
  • branches/1.0.x/testapp/modules/jelix_tests/tests/core.jlocale.html.php

    old new  
    126126 
    127127        $this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale')); 
    128128        // no test2.properties file for fr_CA, so we should have the fr_FR one 
    129        // $this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale', null, 'fr_CA')); 
     129        $this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale', null, 'fr_CA')); 
    130130        // no test3.properties file for fr_CA and fr_FR, so we should have the en_EN one 
    131131        //$this->assertEqual('this is an en_EN sentence test3',jLocale::get('tests3.first.locale', null, 'fr_CA')); 
    132132        //$this->assertEqual('this is an en_EN sentence test3',jLocale::get('tests3.first.locale', null, 'fr_FR')); 
  • branches/1.0.x/lib/jelix/core/jSelector.class.php

    old new  
    352352    * @since 1.0b2 
    353353    */ 
    354354    public $subpath =''; 
    355     /**  
     355    /** 
    356356    * the class name specified in the selector 
    357357    * @since 1.0b2 
    358358    */ 
     
    391391        global $gJConfig; 
    392392        if (!isset($gJConfig->_modulesPathList[$this->module])) { 
    393393            throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    394         }  
     394        } 
    395395        $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix; 
    396396 
    397397        if (!file_exists($this->_path) || strpos($this->subpath,'..') !== false ) { // second test for security issues 
     
    412412} 
    413413 
    414414/** 
    415  * selector for interface  
     415 * selector for interface 
    416416 * 
    417417 * interface is stored in interfacename.iface.php file in the classes/ module directory 
    418418 * or one of its subdirectory. 
     
    428428} 
    429429 
    430430/** 
    431  * selector for interface  
     431 * selector for interface 
    432432 * @package    jelix 
    433433 * @subpackage core_selector 
    434434 * @since 1.0b2 
    435  * @deprecated  
     435 * @deprecated 
    436436 */ 
    437437class jSelectorInterface extends jSelectorIface {} 
    438438 
     
    469469        } 
    470470        $this->locale = $locale; 
    471471        $this->charset = $charset; 
    472         $this->_dirname =  'locales/' .$locale.'/'; 
    473472        $this->_suffix = '.'.$charset.'.properties'; 
    474         $this->_cacheSuffix = '.'.$locale.'.'.$charset.'.php'; 
    475473        $this->_compilerPath=JELIX_LIB_CORE_PATH.'jLocalesCompiler.class.php'; 
    476474 
    477475#if ENABLE_PHP_JELIX 
     
    505503            throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    506504        } 
    507505 
    508         // on regarde si la locale a été redéfini 
    509         $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/'.$this->_dirname.$this->resource.$this->_suffix; 
    510         if (is_readable ($overloadedPath)){ 
    511             $this->_path = $overloadedPath; 
    512             $this->_where = 'overloaded/'; 
    513             return; 
    514         } 
    515         // et sinon, on regarde si la locale existe dans le module en question 
    516         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix; 
     506        $locales = array($this->locale); 
     507        $lang = substr($this->locale,0,2); 
     508        $generic_locale = $lang.'_'.strtoupper($lang); 
     509        if($this->locale !== $generic_locale) 
     510            $locales[] = $generic_locale; 
    517511 
    518         if (!is_readable ($this->_path)){ 
    519             // to avoid infinite loop in a specific lang or charset, we should check if we don't 
    520             // try to retrieve the same message as the one we use for the exception below, 
    521             // and if it is this message, it means that the error message doesn't exist  
    522             // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset 
    523             if($this->toString() == 'jelix~errors.selector.invalid.target'){ 
    524                 $l = 'en_EN'; 
    525                 $c = 'UTF-8'
     512        foreach($locales as $locale){ 
     513            // check if the locale has been overloaded 
     514            $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/locales/'.$locale.'/'.$this->resource.$this->_suffix; 
     515            if (is_readable ($overloadedPath)){ 
     516                $this->_path = $overloadedPath; 
     517                $this->_where = 'overloaded/'; 
     518                $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php'; 
     519                return
    526520            } 
    527             else{ 
    528                 $l = null; 
    529                 $c = null; 
     521            // else check for the original locale file 
     522            $path = $gJConfig->_modulesPathList[$this->module].'/locales/'.$locale.'/'.$this->resource.$this->_suffix; 
     523            if (is_readable ($path)){ 
     524                $this->_where = 'modules/'; 
     525                $this->_path = $path; 
     526                $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php'; 
     527                return; 
    530528            } 
    531             throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); 
    532529        } 
    533         $this->_where = 'modules/'; 
     530 
     531        // to avoid infinite loop in a specific lang or charset, we should check if we don't 
     532        // try to retrieve the same message as the one we use for the exception below, 
     533        // and if it is this message, it means that the error message doesn't exist 
     534        // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset 
     535        if($this->toString() == 'jelix~errors.selector.invalid.target'){ 
     536            $l = 'en_EN'; 
     537            $c = 'UTF-8'; 
     538        } 
     539        else{ 
     540            $l = null; 
     541            $c = null; 
     542        } 
     543        throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); 
    534544    } 
    535545 
    536546    protected function _createCachePath(){ 
Download in other formats: Original Format