The Drupal version of trans (t) filter accepts parameters for replacement in the original string. For example:
{{ 'Expected waiting time is @time minutes'|t({ '@time': time }) }}
The trans filter will replace the @time characters from the original string with the value of the time variable.
In the current implementation of this project, trans is implemented as a pass-through; it returns the original string without change. We should update it to handle replacements for:
@variable
%variable
:variable
From the Drupal docs on how to handle the replacements: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Render%21FormattableMarkup.php/function/FormattableMarkup%3A%3AplaceholderFormat/9.2.x
-
@variable: When the placeholder replacement value is:
- A string, the replaced value in the returned string will be sanitized using \Drupal\Component\Utility\Html::escape().
- A MarkupInterface object, the replaced value in the returned string will not be sanitized.
A MarkupInterface object cast to a string, the replaced value in the returned string be forcibly sanitized using \Drupal\Component\Utility\Html::escape(). Doesn't apply to JS implementations of Twig?
Use this placeholder as the default choice for anything displayed on the site, but not within HTML attributes, JavaScript, or CSS. Doing so is a security risk.
-
%variable: Use when the replacement value is to be wrapped in <em> tags. A call like:
{{ '%output_text'|trans({ '%output_text': 'text output here.' }) }}
makes the following HTML code:
<em class="placeholder">text output here.</em>
As with @variable, do not use this within HTML attributes, JavaScript, or CSS. Doing so is a security risk.
-
:variable: Return value is escaped with \Drupal\Component\Utility\Html::escape() and filtered for dangerous protocols using UrlHelper::stripDangerousProtocols().
This issue depends on #15, "Add placeholder filter implementation".
The Drupal version of
trans(t) filter accepts parameters for replacement in the original string. For example:The
transfilter will replace the@timecharacters from the original string with the value of thetimevariable.In the current implementation of this project,
transis implemented as a pass-through; it returns the original string without change. We should update it to handle replacements for:@variable%variable:variableFrom the Drupal docs on how to handle the replacements: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Render%21FormattableMarkup.php/function/FormattableMarkup%3A%3AplaceholderFormat/9.2.x
This issue depends on #15, "Add placeholder filter implementation".