The Twig "render" function started to return TranslatableMarkup object instead of string for translations

Created on 6 November 2025, 9 days ago

Problem/Motivation

After the upgrade from Drupal Core 11.2.4 to 11.2.5, the Twig function "render" started to return an object instead of the string.

Steps to reproduce

Try this code in any Twig template to reproduce:

{{ dump('Hello one'|t) }}
{{ dump('Hello two'|t|render) }}
{{ dump('Hello three'|t|render ~ '') }}

With Drupal Core 11.2.4 , the "Hello two" will be rendered as string, with 11.2.5 and later - as the TranslatableMarkup instead of the string:

Drupal\Core\StringTranslation\TranslatableMarkup {
  #string: "Hello two"
  #arguments: []
  #translatedMarkup: null
  #options: []
  #stringTranslation: null
}

But if we force converting it to a string using a Twig construction, the conversion works well in the "Hello three" string.

Proposed resolution

This change was merged in the scope of the issue 📌 {% trans %} does not support render array and MarkupInterface valued placeholders Needs work :
https://git.drupalcode.org/project/drupal/-/merge_requests/2968/diffs#64...

       if ($arg instanceof RenderableInterface) {
         $arg = $arg->toRenderable();
       }
+      elseif ($arg instanceof MarkupInterface) {
+        return $arg;
+      }
       elseif (method_exists($arg, '__toString')) {
         return (string) $arg;
       }

If this change is intended, it is a pretty breaking change, so it's better to revert it if there are no real reasons to keep it as is.

And if we need to keep it, we need to create a change record, describing this change.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.2 🔥

Component

render system

Created by

🇦🇲Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024