Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0.0-beta17
Issue links:
Description:
The first argument of t() / TranslatableMarkup() ($string) should never be a variable, i.e. t($variable), and instead should always be a string, for various reasons:
- potx can not scan this
- With locale enabled we potentially translate already translated strings, or end up with dynamic data in locale, which results in a really big locale table
- It is a security risk if it contains user input
In Drupal 8 there is also the risk that we pass in objects if we pass in a variable.
#2570285: Make sure TranslatableMarkup accepts string values only ensures that we no longer accidentally pass in objects (not even if they have a __toString magic method). It throws an exception if $string is not a string.
Impacts:
Module developers