7

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
Paul DelRe
  • 4,003
  • 1
  • 24
  • 26
Lazlo
  • 8,518
  • 14
  • 77
  • 116

2 Answers2

5

You could also use PHP's ucfirst function

{"aaal aala alaa laaa"|@ucfirst}

This will result in

Aaal aala alaa laaa

JochenJung
  • 7,183
  • 12
  • 64
  • 113
2

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

Paul DelRe
  • 4,003
  • 1
  • 24
  • 26
  • Added an example. And my font is Arial. :)... And it does it with P, too. – Lazlo Jun 22 '11 at 20:32
  • Hmm, your examples give me different results where 'l' and 'p' are lowercase. I would guess it's due to a different [locale](http://us2.php.net/manual/en/function.setlocale.php). What is yours set to? `setlocale(LC_CTYPE, NULL);` – Paul DelRe Jun 22 '11 at 20:38
  • I set the locale as you said (before anything in the PHP file). `ucfirst` works correctly, but `|capitalize` is still acting strangely. – Lazlo Jun 22 '11 at 20:47
  • 1
    If you don't need the additional feature of not capitalizing words with digits in the `capitalize` modifier, you could use `ucfirst` as your modifier `{$var|ucfirst}`. – Paul DelRe Jun 22 '11 at 21:03
  • @Paul DelRe: Sure, but that doesn't fix the strangeness. :) – Lazlo Jun 22 '11 at 21:04
  • I'm thinking an `eval()` would reset the locale which Smarty could do to process the compiled template. You could try setting the locale in the template to debug and see if that's what is happening. `{php}setlocale(LC_TYPE, "en_US.UTF-8");{/php}` – Paul DelRe Jun 22 '11 at 21:12