Noticed in issue
#2488304-17: Add more docs that translate() also marks strings as safe, in page template. The following without any additional text it breaks site.
{% trans %}{{ var1 }}{% endtrans %}

Beta phase evaluation

Bug because this can break your site.
Normal because there are workarounds and it is only one of the ways this could be implemented in Twig.
Unfrozen changes Unfrozen because it might change markup, will reevaluate.

Proposed resolution

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions
Once we have a solution, update the issue summary noting if allowed during the beta Instructions
Add automated tests Instructions
Add steps to reproduce the issue Instructions

User interface changes

API changes


lauriii’s picture

Do you mean it breaks site unrecoverable or only when the variable is there?

joelpittet’s picture

Status: Active » Needs review
2.03 KB

Here's a test of exactly what is mentioned in the issue summary. If it fails, this is legit, if not I'll close this issue.

Status: Needs review » Needs work

The last submitted patch, 2: wrapping_var_in-2505517-2.patch, failed testing.

Cottser’s picture

Wait a second though… we don't support this, do we? You need some kind of string, we don't translate just variables because that is bad.

joelpittet’s picture

Status: Needs work » Closed (won't fix)

From the tests:

[20-Nov-2015 20:26:07 UTC] Uncaught PHP Exception Twig_Error_Syntax: "The text to be translated with "trans" can only contain references to simple variables in "core/themes/classy/templates/layout/page.html.twig" at line 51" at /var/www/html/core/lib/Drupal/Core/Template/TwigTransTokenParser.php line 105

So correct we don't support this for two reasons. A) we aren't translating anything... and B) that variable is NULL.

B) may be fixed by #2334319: {% trans %} does not support render array and MarkupInterface valued placeholders

Anyways we don't support this.