View previous topic :: View next topic |
Author |
Message |
rabba Smarty n00b
Joined: 09 Aug 2007 Posts: 2
|
Posted: Fri Aug 10, 2007 8:49 am Post subject: Capitalize |
|
|
Hi,
When I try to capitalize some french word with accent like "électroménager", I have a strange result: "éLectroméNager". I don't know if this bug has already been reported... If you can correct this bug, it's great
Thanks. |
|
Back to top |
|
buzz Smarty n00b
Joined: 23 Aug 2007 Posts: 3
|
Posted: Thu Aug 23, 2007 3:42 am Post subject: |
|
|
i have a similar problem but using upper in spanish...
the text "Niños de México" with upper i obtained "NIñOS DE MéXICO".
i copied a plugin, modifier.upper.php into modifier.mxupper.php and i change the code:
Code: |
function str_to_upper($str){
return strtr($str,
"abcdefghijklmnopqrstuvwxyz".
"áéíóúñäëïöü",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".
"ÁÉÍÓÚÑÄËÏÖÜ");
}
function smarty_modifier_mxupper($string)
{
return str_to_upper($string);
}
|
and now, i have to write into my template {$myText|mxupper} instead {$myText|upper}
i don't know how feasible is my solution but if somebody knows a better solution, please lets me know |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Aug 23, 2007 7:40 am Post subject: |
|
|
Here's an idea:
Create another directory of your private plugins. Then register your plugins_dir as an array: eg: $smarty->plugins_dir = array( '/path/to/my/plugins', SMARTY_DIR . 'plugins'); Smarty will search each directory in order when looking for a requested plugin. So if you put your custom capitilize plugin in your private directory, it will find it there first before ever searching in the distribution plugin directory. That way, you don't need to name your customized plugin "uppermx" -- "upper" will be fine.
HTH
PS and FWIW: there are no plans that I am aware of for Smarty to support internationalization natively until (at least) PHP6. Unfortunate, true, yet merely a practicality based on the current limitations of PHP at this point-in-time...sorry! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Aug 23, 2007 1:55 pm Post subject: |
|
|
You can also register your modifier function:
Code: | $smarty->register_modifier('upper','str_to_upper'); |
That will use your custom function instead of the distribution plugin. |
|
Back to top |
|
dniry Smarty n00b
Joined: 27 Feb 2008 Posts: 1
|
Posted: Wed Feb 27, 2008 7:19 pm Post subject: |
|
|
Or you can edit the Smarty file itself (don't forget to back up first):
SMARTY_DIR/libs/plugins/modifier.upper.php.
I also found this trick on the PHP website. Credits go to its author, "Oliv".
I found it works much better than the strtr function, especially if you are working with UTF-8.
Simply replace the content of the modifier.upper.php file with the following:
Code: | function ucfirstHTMLentity($matches)
{
return "&".ucfirst(strtolower($matches[1])).";";
}
function fullUpper($str)
{
$subject = strtoupper(htmlentities($str, null, 'UTF-8'));
$pattern = '/&([A-Z]+);/';
return preg_replace_callback($pattern, "ucfirstHTMLentity", $subject);
}
function smarty_modifier_upper($string)
{
return fullUpper($string);
} |
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Feb 28, 2008 8:21 am Post subject: |
|
|
dniry wrote: | Or you can edit the Smarty file itself |
ouch. this should obviously be the last resort. |
|
Back to top |
|
Celeb Administrator
Joined: 17 Apr 2007 Posts: 1025 Location: Vienna
|
Posted: Thu Feb 28, 2008 11:12 am Post subject: |
|
|
Tru dat.
Updating your Smarty version will render all your efforts useless, and you'll have to do it all over again. I don't recommend not updating Smarty either _________________ Darn computers always do what I tell them to instead of what I want them to do. |
|
Back to top |
|
conner_bw Smarty Rookie
Joined: 21 Dec 2007 Posts: 17
|
Posted: Thu Oct 23, 2008 8:58 pm Post subject: |
|
|
I have this problem too.
This is a bug. We shouldn't have to work around it. It should be fixed. |
|
Back to top |
|
beldar Smarty n00b
Joined: 26 Apr 2012 Posts: 1
|
Posted: Thu Apr 26, 2012 3:55 pm Post subject: |
|
|
Hi,
I solved this problem simply by editing the original smarty_modifier_upper, changing Code: | return strtoupper($string); | by Code: | return mb_strtoupper($string,'UTF-8'); |
This simple. |
|
Back to top |
|
|