Translate dynamic variable that is an array in twig or using t() How do I translate this in twig? I have this variable in twig that is an array:
$array = [
  ['number' =&gt; 7, 'name' =&gt; 'foo'],
  ['number' =&gt; 8, 'name' =&gt; 'bar'],
  ['number' =&gt; 10, 'name' =&gt; 'baz'],
  // ... and so on and so forth
]

Would like it to be something like this:

The variables are 7 times for foo, 8 times for bar, and 10 times for baz.

Or

The variables are 7 times for foo and 10 times for baz.

Or

The variable is 7 times for foo.

Tried with something like this:
    {% set last = array|last %}
    {% set array = array|slice(0, array.length - 1) %}

    {% trans %}
      &lt;p&gt;The variables are
        {% for i in array %}
          {{ i.number }} times {{ i.name }},
        {% endfor %}
        , and {{ last.number }} number of {{ last.name }}
      .&lt;/p&gt;
    {% endtrans %}

The error I am getting is:

The text to be translated with &quot;trans&quot; can only contain references to simple variables

Could also use t() although I'm not sure how as well. Also tried with something like this:
{% for i in array %}
    {% trans %}{{ i.number }} times {{ i.name }},{% endtrans %}
{% endfor %}
{% trans %}, and {{ last.number }} number of {{ last.name }}{% endtrans %}

Although it doesn't look good from the &quot;User interface translation&quot; page as you would have to translate them separately.
Thanks!
I think it's better to split the content in translatable parts:
  &lt;p&gt;{% trans %}The variables are{% endtrans %}
    {% for i in array %}
      {% trans %}{{ i.number }} times {{ i.name }}{% endtrans %},
    {% endfor %}
    , {% trans %}and {{ last.number }} number of {{ last.name }}{% endtrans %}
  .&lt;/p&gt;

Haven't tested this so I'm not sure if it works. Also, you could use trans as a filter, check this question.