Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty "capitalize" modifier... always capitalizes "L"? ... and "P"?

Quite simply: I'm using Smarty and the |capitalize modifier. It works fine, but when I pass any word with l in it, it capitalizes it, even if it's not at the beginning of the word.

What why?

EDIT: Same happens with p.

Test:

{"abcdefghijklmnopqrstuvwxyz"|capitalize}
{"aaal aala alaa laaa"|capitalize}
{"aaap aapa apaa paaa"|capitalize}

Output:

AbcdefghijkLmnoPqrstuvwxyz
AaaL AaLa ALaa Laaa
AaaP AaPa APaa Paaa
like image 978
Lazlo Avatar asked Jun 22 '11 20:06

Lazlo


2 Answers

You could also use PHP's ucfirst function

{"aaal aala alaa laaa"|@ucfirst}

This will result in

Aaal aala alaa laaa

like image 62
JochenJung Avatar answered Nov 16 '22 09:11

JochenJung


Smarty primarily relies on ucfirst() which is affected by the current locale set in PHP. I have been unable to find information on exactly how this affects the capitalization functions (ucfirst, strtolower, strtoupper, etc), but you can try setting your locale to en_US.UTF-8 (what works on my server) and see how that affects the output.

view locale:

var_dump(setlocale(LC_CTYPE, null));

change locale:

setlocale(LC_CTYPE, "en_US.UTF-8");

Update

Some research leads to a few archives where a customer modifier is written to either pick the local for the modifier or a custom function to set the locale from the template file.

Source 1 Source 2

I haven't been able to reproduce this. Could it be the font you are using (some tail the l)? Do you have code examples?

With Smarty v2

{assign value="let go" var="go"}
{$go|capitalize}
<br/>
{assign value="allow me" var="me"}
{$me|capitalize}

Outputs

Let Go
<br/>
Allow me

like image 2
Paul DelRe Avatar answered Nov 16 '22 10:11

Paul DelRe