Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony/Twig not translating correctly when using message placeholders

I'm trying to use message placeholders with Twig template engine. My navlist.it.yml stores this message and its placeholder:

users:
  label: Gestione utenti %app%

And in my Twig template i'd like to pass app name as a string. So what i'm doing is:

<ul class="nav nav-list">
    <li class="nav-header">
        {{ 'users.label'|trans({'app' : 'Fid'}, 'navlist')|raw }}
    </li>
</ul>

Note i'm using raw because users.label may contain HTML. Output is exactly:

<li class="nav-header">Gestione utenti %Fid%</li>

So message is translated but extra %...% are added. What i'm missing?

like image 535
gremo Avatar asked Mar 03 '12 00:03

gremo


1 Answers

The percent signs are part of the pattern, so you should be adding them to the key of your translation values' array, like this:

{{ 'users.label'|trans({'%app%' : 'Fid'}, 'navlist')|raw }}
like image 154
Maerlyn Avatar answered Nov 10 '22 06:11

Maerlyn