Issue Bug Resolved

#108102Wrong language translation when using Locale in LocalizationUtility::translate as $languageKey

David Henninger 11/13/25, 16:37 updated 10/16/26, 14:20

Description

I ran into an issue when trying to use a Locale when calling LocalizationUtility::translate. Example:

LocalizationUtility::translate("test.label", "my_extension", null, $GLOBALS['TSFE']->language->getLocale());

Let’s assume that the sites current language is German thus it’s Locale would look like this:

object(TYPO3\CMS\Core\Localization\Locale) (7) {
  ["locale":protected]=>
  string(5) "de-DE"
  ["languageCode":protected]=>
  string(2) "de"
  ["languageScript":protected]=>
  NULL
  ["countryCode":protected]=>
  string(2) "DE"
  ["codeSet":protected]=>
  string(5) "UTF-8"
  ["charsetModifier":protected]=>
  NULL
  ["dependencies":protected]=>
  array(0) {
  }
}

*See the empty dependencies? This is what breaks the expected LocalizationUtility behavior and will return the default (english) language for “test.label” instead of German.*
If you just provide “de-DE” as a string instead of the Locale object, translation works fine. Why? Because it then creates a new Locale object based on the string “de-DE” while its dependencies get populated by Locales->getLocaleDependencies:

object(TYPO3\CMS\Core\Localization\Locale) (7) {
  ["locale":protected]=>
  string(5) "de-DE"
  ["languageCode":protected]=>
  string(2) "de"
  ["languageScript":protected]=>
  NULL
  ["countryCode":protected]=>
  string(2) "DE"
  ["codeSet":protected]=>
  NULL
  ["charsetModifier":protected]=>
  NULL
  ["dependencies":protected]=>
  array(1) {
    [0]=>
    string(2) "de"
  }
}

Shouldn’t the dependencies of a Locale always be populated? Or am I assuming/doing something entirely wrong? My use case for this is sending mails in various languages with the backend scheduler (via cli), so I wanted to properly use the Locale instead of its stringified counterpart. This issue occurs both in the frontend and backend.

P.S. keep in mind the localization cache: Once initialized, it will spew out the same language, no matter if you translate with a Locale object or a string as the parameter. So don’t be surprised if Locale-translation suddenly starts working if it is called if it is called after a translation with the Locale-matching language string.

Reviews 2

History 29

  1. Benjamin Kott commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-10-16T14:20:18+00:00" > 10/16/26, 14:20 </span>

    Applied in changeset commit:18765aff565b2f021ea9e870dc65682e8d3a4260.