trans with key value and variable #74

Bacteries opened this Issue Dec 20, 2012 · 2 comments


None yet
3 participants

I use Twig and Twig Extensions (in a non Symfon2 env) and I use key value for my translation.

So I have done this :

{{ "auth.loggedAs"|trans({'%userName%' :}) }}

But it doesn't work :

gettext() expects exactly 1 parameter, 2 given

I check the extension and I guess it's because variable are change in a string, but there is no way to translate using placeholder.
Am I wrong?
(and if you know an extension that can do this?)


Having same issue with text strings (no variables)

<p>{{ 'Click this %a_open% test link %a_close%, friend' | trans({'%a_open%' : '<a href="/test/">', '%a_close%' : '</a>'}) | raw }}</p>

Result is:

gettext() expects exactly 1 parameter, 2 given

PHP code:

echo gettext("Click this %a_open% test link %a_close%, friend", array("%a_open%" => "<a href=\"/test/\">", "%a_close%" => "</a>"));

stof commented Jan 18, 2015

The gettext-based trans filter does not support placeholders like the Symfony translation extension does. Don't confuse both (even though they both use |trans, which is very unfortunate IMO)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment