Ticket #387 (closed bug: fixed)

Opened 1 year ago

Last modified 9 months ago

Boucle infinie avec les messages d'erreurs localisés

Reported by: laurentj Assigned to: Julien
Priority: highest Milestone: Jelix 1.0RC2
Component: jelix:core:jLocale Version: 1.0RC1
Severity: blocker Keywords:
Cc: Php version:
Review: Hosting Provider:
Documentation needed: 0 Blocking:

Description

voir ticket #95

  • créé une appli "test" avec la RC1 (rev 712)
  • appelle index.php : [error 130] Module "test" inconnu ou désactivé < OK, tout va bien
  • change la locale dans le fichier de config pour "de_DE" (le gars veut un site allemand par défaut)
  • appelle index.php : out of memory, boucle infinie

Attachments

bug387.patch (3.3 kB) - added by Julien on 12/19/07 17:38:31.
fix by using an internal "last-chance fallback" locale, by default it is en_EN

Change History

12/19/07 14:12:45 changed by Julien

  • owner changed from laurentj to Julien.

Je prends en charge.

Normalement je sors quelque chose dans l'après-midi.

12/19/07 17:38:31 changed by Julien

  • attachment bug387.patch added.

fix by using an internal "last-chance fallback" locale, by default it is en_EN

12/19/07 17:48:04 changed by Julien

Voilà le patch.

Ca règle le problème évoqué ce matin.

Et ça m'a donné de nouvelles perspectives pour améliorer mon patch du ticket #95.

On verra ça début janvier.

++ Julien

12/20/07 23:50:03 changed by laurentj

  • status changed from new to closed.
  • resolution set to fixed.

Ça ne rêgle pas tout, en particulier dans le cas où la locale n'existe pas du tout (dans un autre contexte que celui du bug). Je n'ai donc pas pris en compte ton patch sauf au niveau de $this->_cacheSuffix.

Pour info, voici la correction que j'ai appliqué dans le trunk (en plus de tests unitaires) :

Index: lib/jelix/core/jSelector.class.php
===================================================================
--- lib/jelix/core/jSelector.class.php  (révision 714)
+++ lib/jelix/core/jSelector.class.php  (copie de travail)
@@ -460,7 +460,7 @@
         $this->charset = $charset;
         $this->_dirname =  'locales/' .$locale.'/';
         $this->_suffix = '.'.$charset.'.properties';
-        $this->_cacheSuffix = '.'.$charset.'.php';
+        $this->_cacheSuffix = '.'.$locale.'.'.$charset.'.php';
         $this->_compilerPath=JELIX_LIB_CORE_PATH.'jLocalesCompiler.class.php';

 #if ENABLE_PHP_JELIX
@@ -489,6 +489,8 @@
     protected function _createPath(){
         global $gJConfig;
         if(!isset($gJConfig->_modulesPathList[$this->module])){
+            if ($this->module == 'jelix')
+                throw new Exception('jelix module is not enabled !!');
             throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString());
         }

@@ -503,7 +505,15 @@
         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix;

         if (!is_readable ($this->_path)){
-            throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"));
+            // to avoid infinite loop in a specific lang, we should check if we don't
+            // try to retrieve the same message as the one we use for the exception below,
+            // and if it is this message, it means that the error message doesn't exist
+            // in the specific lang, so we retrieve it in en_EN language
+            if($this->toString() == 'jelix~errors.selector.invalid.target')
+                $l = 'en_EN';
+            else
+                $l=null;
+            throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "locale"),1,$l);
         }
         $this->_where = 'modules/';
     }
Index: lib/jelix/core/jException.lib.php
===================================================================
--- lib/jelix/core/jException.lib.php   (révision 714)
+++ lib/jelix/core/jException.lib.php   (copie de travail)
@@ -119,14 +119,15 @@
      * @param string $localekey a locale key
      * @param array $localeParams parameters for the message (for sprintf)
      * @param integer $code error code (can be provided by the localized message)
+     * @param string $lang
      */
-    public function __construct($localekey, $localeParams=array(), $code = 1) {
+    public function __construct($localekey, $localeParams=array(), $code = 1, $lang=null) {

         $this->localeKey = $localekey;
         $this->localeParams = $localeParams;

         try{
-            $message = jLocale::get($localekey, $localeParams);
+            $message = jLocale::get($localekey, $localeParams, $lang);
         }catch(Exception $e){
             $message = $e->getMessage();
         }

03/06/08 13:33:34 changed by laurentj

  • docneeded changed.
  • review changed.
  • component changed from jelix:core to jelix:core:jLocale.
Download in other formats: Comma-delimited Text Tab-delimited Text RSS Feed