2
votes

When I go to my page login in localhost :

mylocal.com/app_dev.php/login, I have this error :

enter image description here

An exception has been thrown during the rendering of a template ("Warning: gettext() expects exactly 1 parameter, 3 given").

On this ligne of template :

<div class="form-group">
   <input type="text" id="username" name="_username" value="{{ last_username }}" required="required" placeholder="{{ 'security.login.username'|trans }}" class="form-control" />
</div>

My composer.json :

"require": {
        "php": ">=7.1",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "friendsofsymfony/jsrouting-bundle": "^1.6",
        "friendsofsymfony/user-bundle": "2.0.2",
        "incenteev/composer-parameter-handler": "^2.0",
        "knplabs/doctrine-behaviors": "^1.4",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^5.0.0",
        "symfony/assetic-bundle": "^2.8",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.6.4",
        "symfony/symfony": "3.4.*",
        "twig/twig": "^2.0",
        "twig/extensions": "^1.5"
    },

My version :

php: PHP 7.2.2-3+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Feb 6 2018 16:11:23) ( NTS )

apache: Server version: Apache/2.4.18 (Ubuntu)

5
Is it possible to provide us the full trace of exception? The symfony/translation component seems to be missing. - Alexandre Tranchant
@AlexandreT I have the same problem and installing symfony/translation component doesn't change anything. - Dado
@dado: Is the answer below fixing your problem? - Alexandre Tranchant
@AlexandreT Yes, in my composer.json there is a "twig/extensions": "^1.5" and after disabeling "Twig_Extensions_Extension_I18n" in my configuration i was able to render my form without any probelms als all works fine again. And i hope my post below will help someone with same problems to fix it faster. - Dado

5 Answers

3
votes

If you use Twig-extensions, it may com from the i18n Extension. So to quickly fix it, juste disable the i18n Extension.

http://twig-extensions.readthedocs.io/en/latest/i18n.html

1
votes

If someone has the same problem with An exception has been thrown during the rendering of a template ("Warning: gettext() expects exactly 1 parameter, 3 given"). check your config for registered twig extension and remove it:

twig.extension.i18n:
    class: Twig_Extensions_Extension_I18n
    tags:
        - { name: twig.extension }
0
votes

I believe that it is because of your translations. Twig expects {{ }} to be a php variable not a string. Try this:

{% trans %}security.login.username{% endtrans %}
0
votes

Make sure that symfony/twig-bridge is installed

0
votes
<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" placeholder="{{ 'security.login.username'|trans }}" class="form-control" />

I'm not sure why are using quotes for security.login.username, looks like you are trying to get some value from security object, if so then try removing quotes like this :

<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" placeholder="{{ security.login.username|trans }}" class="form-control" />