简体   繁体   中英

Is it possible to render raw variable brackets in twig within translation tags

We're looking for a new way to create multi language email templates. We got the idea to use inky in twig to create clean email HTML and render translations. The problem is that we have Sendgrid (handlebars) that renders variables the same way as twig.

Is there a solution to create a translation in twig having the {{ }} intact. We don't want to translate around the brackets because that could not be compatible with the language its spelling.

example

{% trans %}I am a {{ job }}{% endtrans %}

gives the following error:

A message inside a trans tag must be a simple text.

You can use the verbatim tag to escape twig delimiters (or raw in twig 1 and 2).

The verbatim tag marks sections as being raw text that should not be parsed.

{% trans %}
    {% verbatim %}
        I am a {{ job }}
    {% endverbatim %}
{% endtrans %}

Another simple way would be to just output your twig delimiters as a string:

{% trans %}I am a {{ '{{' }} job {{ '}}' }}{% endtrans %}

You could simply fix this by using the filter option:

{{ 'i am {{ job }}'| trans({},'domain') }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM