developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#1252 closed enhancement (fixed)

Langue par défaut

Reported by: hadrien Owned by: Julien
Priority: normal Milestone: Jelix 1.3 beta 1
Component: jelix:core:jLocale Version: 1.2
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: yes
Hosting Provider: Php version:

Description

Un patch pour avoir un fallback sur une langue par défaut quand une locale n'existe pas dans la langue demandée. Il faudra prélablement configurer defaultlocale dans le defaultconfig.ini.php. C'est une variable différente de gJConfig->locale qui est la langue globale, plutôt que la langue par défaut.

diff --git a/lib/jelix/core/jLocale.class.php b/lib/jelix/core/jLocale.class.php
index 79a44dd..26d8a5d 100644
--- a/lib/jelix/core/jLocale.class.php
+++ b/lib/jelix/core/jLocale.class.php
@@ -85,12 +85,14 @@ class jLocale {
         //try to get the message from the bundle.
         $string = $bundle->get ($file->messageKey, $file->charset);
         if ($string === null) {
+            if (!isset($gJConfig->defaultlocale) or $locale == $gJConfig->defaultlocale) {
+                throw new Exception('(210)The given locale key "'.$file->toString().'" does not exists in the default lang for the '.$file->charset.'
+            }
             //if the message was not found, we're gonna
             //use the default language and country.
             if ($locale == $gJConfig->locale) {
-                throw new Exception('(210)The given locale key "'.$file->toString().'" does not exists in the default lang for the '.$file->charset.'
+                return jLocale::get ($key, $args, $gJConfig->defaultlocale);
             }
-            return jLocale::get ($key, $args, $gJConfig->locale);
         }
         else {
             //here, we know the message

Change History (5)

comment:1 Changed 10 years ago by laurentj

  • Milestone set to Jelix 1.3

comment:2 Changed 10 years ago by hadrien

Voici un patch qui marche mieux :

diff --git a/lib/jelix/core/jLocale.class.php b/lib/jelix/core/jLocale.class.php
index 79a44dd..64a5f34 100644
--- a/lib/jelix/core/jLocale.class.php
+++ b/lib/jelix/core/jLocale.class.php
@@ -66,11 +66,15 @@ class jLocale {
         }
         catch (jExceptionSelector $e) {
             if ($e->getCode() == 12) throw $e;
-            if ($locale === null)  $locale = $gJConfig->locale;
-            if ($charset === null) $charset = $gJConfig->charset;
-            throw new Exception('(200)The given locale key "'.$key
-                                .'" is invalid (for charset '.$charset
-                                .', lang '.$locale.')');
+            //if the message was not found, we're gonna
+            //use the default language and country.
+            if (!isset($gJConfig->defaultlocale) or $locale === $gJConfig->defaultlocale) {
+                throw new Exception('(210)The given locale key "'.$file->toString().'" does not exists in the default lang for the '.$file->charset.'
+            }
+            else
+            {
+                return jLocale::get ($key, $args, $gJConfig->defaultlocale);
+            }
         }
 
         $locale = $file->locale;

comment:3 Changed 10 years ago by laurentj

  • review changed from review? to review-

you don't take care about the charset...

comment:4 Changed 9 years ago by laurentj

  • Resolution set to fixed
  • review review- deleted
  • Status changed from new to closed

j'ai modifié le patch légèrement, et j'ai changé le nom defaultLocale en fallbackLocale. https://bitbucket.org/jelix/jelix-trunk/changeset/37c04c2bad9c https://bitbucket.org/jelix/jelix-trunk/changeset/d50c15302782

comment:5 Changed 9 years ago by laurentj

  • Documentation needed set
Note: See TracTickets for help on using tickets.