Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Capitalize

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
rabba
Smarty n00b


Joined: 09 Aug 2007
Posts: 2

PostPosted: Fri Aug 10, 2007 8:49 am    Post subject: Capitalize Reply with quote

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 Very Happy

Thanks.
Back to top
View user's profile Send private message
buzz
Smarty n00b


Joined: 23 Aug 2007
Posts: 3

PostPosted: Thu Aug 23, 2007 3:42 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Aug 23, 2007 7:40 am    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Aug 23, 2007 1:55 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
dniry
Smarty n00b


Joined: 27 Feb 2008
Posts: 1

PostPosted: Wed Feb 27, 2008 7:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Feb 28, 2008 8:21 am    Post subject: Reply with quote

dniry wrote:
Or you can edit the Smarty file itself


ouch. this should obviously be the last resort.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Thu Feb 28, 2008 11:12 am    Post subject: Reply with quote

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 Smile
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
conner_bw
Smarty Rookie


Joined: 21 Dec 2007
Posts: 17

PostPosted: Thu Oct 23, 2008 8:58 pm    Post subject: Reply with quote

I have this problem too.

This is a bug. We shouldn't have to work around it. It should be fixed.
Back to top
View user's profile Send private message
beldar
Smarty n00b


Joined: 26 Apr 2012
Posts: 1

PostPosted: Thu Apr 26, 2012 3:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP