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.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.
Opened 11 years ago
Last modified 9 years ago
#1107 reviewing enhancement
Gestion des paramètres nommés dans jLocale
Reported by: | hadrien | Owned by: | laurentj |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | jelix:core | Version: | 1.1.6 |
Severity: | normal | Keywords: | jlocale |
Cc: | Blocked By: | ||
Blocking: | Documentation needed: | no | |
Hosting Provider: | Php version: |
Description
J'ai rajouté la possibilité d'utiliser des paramètres nommés dans jLocale :
diff --git a/lib/jelix/core/jLocale.class.php b/lib/jelix/core/jLocale.class.php index 84a02af..c525c57 100644 --- a/lib/jelix/core/jLocale.class.php +++ b/lib/jelix/core/jLocale.class.php @@ -93,7 +93,23 @@ class jLocale { else { //here, we know the message if ($args !== null && $args !== array()) { - $string = call_user_func_array('sprintf', array_merge (array ($string), is_array ($args) ? $args : array ($args))); + + // check if $args contains named params + $namedParams = false; + foreach ($args as $k => $a) { + if (is_string($k)) { + $string = str_replace( + '@@' . $k . '@@', + $a, + $string + ); + $namedParams = true; + } + } + if ($namedParams === false) + { + $string = call_user_func_array('sprintf', array_merge (array ($string), is_array ($args) ? $args : array ($args))); + } } return $string; }
Ça fonctionne de la sorte :
{jlocale 'module~file.key', array( 'variable' => 'mon texte variable' )}
ou dans un controller :
jLocale::get( 'module~file.key', array( 'variable' => 'mon texte variable' ) );
Et dans le fichier de locale.properties, ça donne ça :
key = Ce texte contient @@variable@@
Et ça reste bien évidemment compatible avec les actuels paramètres ordonnés.
Attachments (1)
Change History (4)
comment:1 Changed 11 years ago by foxmask
Changed 11 years ago by hadrien
comment:2 Changed 11 years ago by hadrien
Désolé, je peux pas faire mieux qu'un diff de la version 1.1.6 de jelix. Le voici en fichier attaché avec un fix.
comment:3 Changed 9 years ago by laurentj
- Status changed from new to reviewing
Note: See
TracTickets for help on using
tickets.
bonjour adrien,
je crois que le "chef" ne va pas etre d'accord avec ton "patch" brute de fonderie
il faudrait suivre http://developer.jelix.org/wiki/fr/patchs pour bien faire :-)
pour la faire courte, il faudrait au moins mettre le diff en pièce jointe du ticket pour tester le patch.