Active
Project:
Drupal core
Version:
main
Component:
cache system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Jul 2026 at 10:36 UTC
Updated:
20 Jul 2026 at 10:36 UTC
Jump to comment: Most recent
Responses that contain translated interface strings (with t()) require the languages:language_interface cache context to correctly vary based on the current language.
This cache context is usually added by the rendering system so developers don't have to think about adding it explicitly.
But when returning a custom JSON response (without any rendering), you have to explicitly add the cache context:
$response = new CacheableAjaxResponse(['title' => t('foo')]);
IMHO this is bad DX and easy to forget.
Maybe we could have something similar to EarlyRenderingControllerWrapperSubscriber that triggers an exception when using translated strings in a cacheable response that does not have the correct cache context.
Comments