Q:

twig: set variable with function

I want to set a variable with the content of a translation function:
{% set somevar = XXXXX %}

Within content, I call the translation like this, but I fail to put the function result into the var:
{% trans into _locale %}somefield{% endtrans %} 

I tried many different aproaches, but I always failed, any hint is highly appreciated.

A:

Try with:
{% set somevar %}
    {% trans into _locale %}somefield{% endtrans %} 
{% endset %}

A:

Found solution:
{% set somevar = 'somefield' %}

{{ somevar|trans(_locale) }}

