#108102Wrong language translation when using Locale in LocalizationUtility::translate as $languageKey
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
-
Gerrit Code Review pushed patch set 1 for main to change 95443 status
NewUnder Review <span data-processor="relativetime" data-value="2026-08-26T23:47:01+00:00" > 08/26/26, 23:47 </span> -
Gerrit Code Review pushed patch set 2 for main to change 95443 <span data-processor="relativetime" data-value="2026-09-23T15:45:51+00:00" > 09/23/26, 15:45 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 95443 <span data-processor="relativetime" data-value="2026-09-23T15:45:57+00:00" > 09/23/26, 15:45 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 95443 <span data-processor="relativetime" data-value="2026-10-15T12:46:42+00:00" > 10/15/26, 12:46 </span>
-
Gerrit Code Review pushed patch set 5 for main to change 95443 <span data-processor="relativetime" data-value="2026-10-16T11:45:06+00:00" > 10/16/26, 11:45 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 96758 <span data-processor="relativetime" data-value="2026-10-16T14:00:21+00:00" > 10/16/26, 14:00 </span>
-
Gerrit Code Review pushed patch set 2 for 14.3 to change 96758 <span data-processor="relativetime" data-value="2026-10-16T14:02:47+00:00" > 10/16/26, 14:02 </span>
-
Benjamin Kott commented and changed status
Under ReviewResolved done0 %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.
I can confirm this issue for TYPO3 14.0.1