- 1
[Opened] [Résolu] Problème avec capitalize et accent
Posted by benjamin on 01/25/2008 17:21
Bonjour,
dans un fichier de locale, j'ai un texte qui est "édition". Je réutilise ce texte dans un template auquel j'applique le modificateur "|capitalize". J'espérais obtenir "Édition" ou au moins "Edition" mais "édition" reste en minuscule. En revanche si je mets "edition" j'obtiens bien le résultat attendu : "Edition"...
Merci
NB : j'en profite aussi pour demander s'il y a un modifier qui permet de mettre en majuscule la 1ère lettre du 1er mot (et pas de chaque mot contrairement à capitalize) se basant sur la fonction php 'ucfirst'?
Jelix 1.0.2 - mise en production réussie : http://www.autolux.ca
[Opened] Re: Problème avec capitalize et accent
Posted by laurentj on 01/25/2008 22:37
Bonjour,
Le modificateur "capitalize" est en fait la fonction ucwords de PHP. Donc je ne peux pas y faire grand chose. (aaah php et tout ses bugs...).
Sinon non, il n'y a pas de modificateur similaire à ucfirst. Mais ce n'est pas bien compliqué à faire, et tu l'ajoutes dans le répertoire plugins de ton appli.
[Opened] Re: Problème avec capitalize et accent
Posted by benjamin on 01/25/2008 22:41
Ok, merci.
Si ça peut servir à quelqu'un, voilà mon plugin :
<?php
/**
* Plugin from smarty project and adapted for jtpl
* @package jelix
* @subpackage jtpl_plugin
* @author
* @contributor Benjamin Cartereau (utf8 compliance)
* @copyright
* @link http://smarty.php.net/
* @link http://jelix.org/
* @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
*/
/**
* Modifier plugin : uppercase the first letter
*
* Capitalize the first letter of a string (unicode aware), optionally converting
* the rest of the string to lower case, and using the $encoding character encoding.
* <pre>{$mytext|ucfirst}
* {$mytext|ucfirst:true}
* {$mytext|ucfirst:true:'ISO-8859-15'}
* </pre>
* @param string
* @param bool $lc_remaining
* @param string $encoding
* @return string
*/
function jtpl_modifier_common_ucfirst($string, $lc_remaining = false, $encoding = "utf-8")
{
$ucfirst_string = '';
if (!empty($string))
{
$firstletter = mb_substr($string, 0, 1, $encoding);
$stringTail = mb_substr($string, 1, strlen($string), $encoding);
$ucfirst_string = mb_strtoupper($firstletter, $encoding) . ($lc_remaining?mb_strtolower($stringTail, $encoding):$stringTail);
}
return $ucfirst_string;
}
?>
Jelix 1.0.2 - mise en production réussie : http://www.autolux.ca
- 1

