There are a few questions here, so let's cover them.
1) Twig's behavior is not like a Doctrine request, where each parameter should be limited. You can pass an array containing unused parameters to trans , so if you do not want to specify {'key': 'value', 'key2': 'value2'...} for the filter, just pass the entire array (example: | trans(array) ). This is @Luke.
2) You can translate a block of texts in several ways, the simplest is {% set %} . The {% set %} tag can be used in two ways:
{% set var = expression %} or {% set var1, var2 = expression1, expression2 %} is the most famous and used way: you simply add some value to one or more variables.
{% set var %} block of text {% endset %} allows you to set the entire block of text inside this variable. This is useful if you want to put this block in a filter (for example, escape or, in your case, trans ).
So, to translate a block of text, you will do something like:
{% set variable %} block to translate %placeholder% {% endset %} {{ variable | trans(array) }}
In any case, I donβt see interest in translating the whole block at a time: we usually use | trans | trans after the property (e.g. say.hello ), and I cannot imagine your xlf / yml translation file with such a construction. If you want to use the translator only to fill in placeholders, just use Twig as written for this work :-)
3) About replacing placeholder with %placeholder% in your array parameters: Twig point: put what you want as a placeholder. That way, if your translated sentence contains a few % , you can use $something$ , #something# or even something as a placeholder.
If your array keys do not contain those % , you need to add them, you have no choice. If you really want to do this in a Twig file, you can create a macro that will do the job for you and put it in a file that you import in your base layout.
Something like:
{% macro trans_pct(property, params) %} {% set newParams = [] } {% if params %} {% for key, value in params %} {% set newParams['%' ~ key ~ '%'] = value %} {% endfor %} {% endif %} {{ property | trans(newParams) }} {% endmacro %}
And then use it with {{ _self.trans_pct('hello.say', array) | trim }} {{ _self.trans_pct('hello.say', array) | trim }} .
Notes:
_self is the template in which the macro is stored (see details).
/ li>trim used because I wrote a macro with indentation and line breaks (this one is clean for reading). These spaces are printed by default.