Needs review
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
10 Jun 2020 at 23:50 UTC
Updated:
26 Sep 2026 at 22:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
andypostSuggested changes
Comment #8
smustgrave commentedTriggering for 10.1 tests
Comment #9
smustgrave commentedSame as the one I just RTBC tests are green and seem like a good refactoring.
Comment #10
alexpottIf we want to do this then I think we should deprecate
\Drupal\views\Views::t()and replace all the calls to it withnew TranslatableMarkup()since this is what we tell people to use in static methods.Comment #14
ptmkenny commentedThis issue has stalled, but I would like to work on it because the static translation caching breaks badly when using FrankenPHP in worker mode (because Drupal is only bootstrapped once for many requests, the cache goes stale after the first request).
I propose expanding the scope of the issue and including the follow-up from @alexpott in #10. I'm including a new IS below; if this is too big of a scope change, just let me know and I'll remove this comment and create a new issue instead.
Problem/Motivation
Views::t() stores the
string_translationservice in Views::$translationManager. Views::getHandlerTypes() stores its labels in Views::$handlerTypes. This static caching is fine for the way Drupal has traditionally been deployed, but it doesn't work for persistent app servers like FrankenPHP.Each label references the translation manager. TranslatableMarkup::render() stores the translated text. So, resetting
$translationManagerdoes not refresh the labels.How does this break? A persistent worker serves many requests in one process, so later requests get their labels in the first request's language. In addition, the old service and its container are kept in memory, wasting space.
Steps to reproduce
string_translationto a translation manager with English as the default language.Views::getHandlerTypes()and render['field']['title'].string_translationwith a Japanese translation manager, in the same container or a new one.Views::getHandlerTypes()again.['field']['title']still renders the English text.Proposed resolution
Return a new array of new
TranslatableMarkupobjects on each call. Labels are translated when rendered.Deprecate
Views::t()and the two unused properties.AI disclosure: I used AI to help me prepare the new IS and also write the MR (Opus 5.5 and Astra).
Comment #16
ptmkenny commentedOk, I proposed expanding the scope of this MR in #14 as well as added an MR and a change record, so I'm tentatively setting this to "Needs Review."
I did not measure the performance impact of removing the static caching because I don't know how to do that.
Comment #17
nicxvan commentedIf we do still need caching we can use a memory cache then you can reset it as needed.