TranslatableMarkup does not seem to use current but rather default language

Created on 13 October 2023, over 1 year ago
Updated 15 February 2024, about 1 year ago

We encountered this behavior when using the |t filter inside a twig file after having set a different language using \Drupal::languageManager()->setConfigOverrideLanguage() and noticing this language wasn't being picked up.

The call stack for that filter boils down to:

  • The procedural t() function gets called
  • This creates a TranslatableMarkup with no langcode being passed to the options
  • This makes its way to TranslationManager::doTranslate() where the default (not current!) language gets filled in

Yet the documentation for TranslatableMarkup specifically states:

   * @param array $options
   *   (optional) An associative array of additional options, with the following
   *   elements:
   *   - 'langcode' (defaults to the current language): A language code, to
   *     translate to a language other than what is used to display the page.

Clearly it's not defaulting to the current language, but rather the default language. Or are we misinterpreting what's happening here? Marking as a support request as it may not be a bug but rather a misinterpretation.

πŸ’¬ Support request
Status

Active

Version

11.0 πŸ”₯

Component
Language systemΒ  β†’

Last updated 7 days ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

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

Comments & Activities

Production build 0.71.5 2024