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) |
|---|
-
trunk/testapp/modules/jelix_tests/tests/core.jlocale.html_cli.php
old new 127 127 128 128 $this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale')); 129 129 // 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')); 131 131 // no test3.properties file for fr_CA and fr_FR, so we should have the en_EN one 132 132 //$GLOBALS['gJConfig']->locale = 'en_EN'; 133 133 //$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 352 352 * @since 1.0b2 353 353 */ 354 354 public $subpath =''; 355 /** 355 /** 356 356 * the class name specified in the selector 357 357 * @since 1.0b2 358 358 */ … … 391 391 global $gJConfig; 392 392 if (!isset($gJConfig->_modulesPathList[$this->module])) { 393 393 throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 394 } 394 } 395 395 $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix; 396 396 397 397 if (!file_exists($this->_path) || strpos($this->subpath,'..') !== false ) { // second test for security issues … … 412 412 } 413 413 414 414 /** 415 * selector for interface 415 * selector for interface 416 416 * 417 417 * interface is stored in interfacename.iface.php file in the classes/ module directory 418 418 * or one of its subdirectory. … … 428 428 } 429 429 430 430 /** 431 * selector for interface 431 * selector for interface 432 432 * @package jelix 433 433 * @subpackage core_selector 434 434 * @since 1.0b2 435 * @deprecated 435 * @deprecated 436 436 */ 437 437 class jSelectorInterface extends jSelectorIface {} 438 438 … … 469 469 } 470 470 $this->locale = $locale; 471 471 $this->charset = $charset; 472 $this->_dirname = 'locales/' .$locale.'/';473 472 $this->_suffix = '.'.$charset.'.properties'; 474 $this->_cacheSuffix = '.'.$locale.'.'.$charset.'.php';475 473 $this->_compilerPath=JELIX_LIB_CORE_PATH.'jLocalesCompiler.class.php'; 476 474 477 475 #if ENABLE_PHP_JELIX … … 505 503 throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 506 504 } 507 505 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; 517 511 518 if (!is_readable ($this->_path)){519 // to avoid infinite loop in a specific lang or charset, we should check if we don't520 // 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 exist522 // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset523 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; 526 520 } 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; 530 528 } 531 throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c);532 529 } 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); 534 544 } 535 545 536 546 protected function _createCachePath(){ -
branches/1.0.x/testapp/modules/jelix_tests/tests/core.jlocale.html.php
old new 126 126 127 127 $this->assertEqual('ceci est une phrase fr_FR test2',jLocale::get('tests2.first.locale')); 128 128 // 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')); 130 130 // no test3.properties file for fr_CA and fr_FR, so we should have the en_EN one 131 131 //$this->assertEqual('this is an en_EN sentence test3',jLocale::get('tests3.first.locale', null, 'fr_CA')); 132 132 //$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 352 352 * @since 1.0b2 353 353 */ 354 354 public $subpath =''; 355 /** 355 /** 356 356 * the class name specified in the selector 357 357 * @since 1.0b2 358 358 */ … … 391 391 global $gJConfig; 392 392 if (!isset($gJConfig->_modulesPathList[$this->module])) { 393 393 throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 394 } 394 } 395 395 $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix; 396 396 397 397 if (!file_exists($this->_path) || strpos($this->subpath,'..') !== false ) { // second test for security issues … … 412 412 } 413 413 414 414 /** 415 * selector for interface 415 * selector for interface 416 416 * 417 417 * interface is stored in interfacename.iface.php file in the classes/ module directory 418 418 * or one of its subdirectory. … … 428 428 } 429 429 430 430 /** 431 * selector for interface 431 * selector for interface 432 432 * @package jelix 433 433 * @subpackage core_selector 434 434 * @since 1.0b2 435 * @deprecated 435 * @deprecated 436 436 */ 437 437 class jSelectorInterface extends jSelectorIface {} 438 438 … … 469 469 } 470 470 $this->locale = $locale; 471 471 $this->charset = $charset; 472 $this->_dirname = 'locales/' .$locale.'/';473 472 $this->_suffix = '.'.$charset.'.properties'; 474 $this->_cacheSuffix = '.'.$locale.'.'.$charset.'.php';475 473 $this->_compilerPath=JELIX_LIB_CORE_PATH.'jLocalesCompiler.class.php'; 476 474 477 475 #if ENABLE_PHP_JELIX … … 505 503 throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 506 504 } 507 505 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; 517 511 518 if (!is_readable ($this->_path)){519 // to avoid infinite loop in a specific lang or charset, we should check if we don't520 // 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 exist522 // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset523 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; 526 520 } 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; 530 528 } 531 throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c);532 529 } 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); 534 544 } 535 545 536 546 protected function _createCachePath(){
