Issue Bug Closed

#100030Translation handling: Fallback chain is broken if backend user is logged in.

Marc Willmann 02/24/23, 22:29 updated 07/09/24, 12:46

Description

According to https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Localization/XliffFormat.html TYPO3 supports a fallbackchain for locallang.xlf files with region-specific prefix.

As I understand correctly the feature SHOULD work this way:

If I have a locale of e.g. de-DE.UTF-8 TYPO3 will use the language labels in de_DE.locallang.xlf. If this file does not exist the label from de.locallang.xlf will be used. And last but not least the original label from locallang.xlf comes into effect.

This behaviour is broken in 12.2.0

If a BE user is logged in and uses the Backend (!) with german translation, the file ‘de_DE.locallang.xlf’ is ignored when rendering the frontend! (thanks for the acceptance test in our project which has detected this error ;)

If no BE user is logged in, the file de.locallang.xlf is ignored.

So, as a temporary workaround I have a symlink de.locallang.xlf which points to de_DE.locallang.xlf to tackle both use cases.

I expect this bug is related to vendor/typo3/cms-extbase/Classes/Utility/LocalizationUtility.php

/**
     * Resolves the currently active language key.
     */
    protected static function getLanguageKey(): string
    {
        if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
        ) {
            // Frontend application
            $siteLanguage = self::getCurrentSiteLanguage();

            // Get values from site language
            if ($siteLanguage !== null) {
                return $siteLanguage->getTypo3Language();
            }
        } elseif (!empty($GLOBALS['BE_USER']->user['lang'])) {
            return $GLOBALS['BE_USER']->user['lang'];
        }
        return 'default';
    }

Reviews 1