Project

General

Profile

Actions

Bug #100030

closed

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

Added by Marc Willmann about 1 year ago. Updated about 1 year ago.

Status:
Resolved
Priority:
Must have
Assignee:
Category:
-
Target version:
-
Start date:
2023-02-24
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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';
    }

Files

Translation.png (40.4 KB) Translation.png Marc Willmann, 2023-02-27 09:37

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #100176: Translations not available in v12.2 when using language key with country in site configResolved2023-03-15

Actions
Related to TYPO3 Core - Bug #100255: Language of backend user influence FE translationsResolved2023-03-22

Actions
Actions #1

Updated by Benni Mack about 1 year ago

  • Status changed from New to Needs Feedback

Hi Marc,

just to get this right... you have a be_users, which logs into the backend, and you expect this user to get the labels from "de_DE.locallang.xlf" but it does not respect that?

So my question would be... does you backend user record contains the value "de_DE" in the "lang" field?

Actions #2

Updated by Marc Willmann about 1 year ago

Hi Benni,

Please see attached screenshot. I have a label in the frontend ("to top", "nach oben") which is delivered by a f:translate-VH in the page layout. I expect that this label is chosen according the language which is used in the frontend. In both cases this is german, which is configured as de_DE.UTF-8 in the sites configuration).

In the left part of the screenshot I am logged in as BE user (with language de), in the right part it's an anonymous browser without logged in BE user. As you can see in the one case (BE user logged in with german backend) I get the translated string; in the other the original string from locallang.xml.

I expect that the BE user and it's chosen backend language is not affected to the frontend translation, but it is.

In this case we have had v11 TYPO3 (now updated to 12.2) with the respecting translation files (locallang.xlf and de.locallang.xlf) which is also sufficient for this website. But I have to copy/symlink de.locallang.xlf to de_DE.locallang.xlf to get the translated string "nach oben" in both cases (BE user is logged in//BE user is not logged in).

If you have further questions, I'm happy to help.

Actions #3

Updated by Kevin Appelt about 1 year ago

I would go even further and would not expect the configured backend language of the user to affect the frontend language (especially not only of f:translate) at all!

Regarding the fallback chain I would expect the system to try de_DE.locallang.xlf, if not present de.locallang.xlf, if not present locallang.xlf.
This would allow us to have language versions of the website like de_DE, de_AT and de_CH and only require a de.locallang.xlf which might get overrides from files like de_CH.locallang.xlf if a label needs to be overridden for that language version.

Actions #4

Updated by Benni Mack about 1 year ago

Kevin Appelt wrote in #note-3:

I would go even further and would not expect the configured backend language of the user to affect the frontend language (especially not only of f:translate) at all!

Regarding the fallback chain I would expect the system to try de_DE.locallang.xlf, if not present de.locallang.xlf, if not present locallang.xlf.
This would allow us to have language versions of the website like de_DE, de_AT and de_CH and only require a de.locallang.xlf which might get overrides from files like de_CH.locallang.xlf if a label needs to be overridden for that language version.

That was my exact intention (and I wonder why it's not working).

Actions #5

Updated by Marc Willmann about 1 year ago

Is there any more feedback needed (aka "is the ticket status correct")?

Actions #6

Updated by Benni Mack about 1 year ago

  • Status changed from Needs Feedback to Accepted
  • Assignee set to Benni Mack

All good, I'm currently sick but will tackle it next week!

Actions #7

Updated by Marc Willmann about 1 year ago

Get well soon!

Actions #8

Updated by Benni Mack about 1 year ago

Hi Marc,

so I had a quick look at your issue.

I can see that my frontend (v12.3-dev) also returns "de" but this is because my site configuration contains a "typo3Language: de" setting. If I remove this, it worked. Can you recheck this, also with the latest v12.3 status?

Actions #9

Updated by Gerrit Code Review about 1 year ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78192

Actions #10

Updated by Gerrit Code Review about 1 year ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78192

Actions #11

Updated by Benni Mack about 1 year ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #12

Updated by Timo Webler about 1 year ago

  • Related to Bug #100176: Translations not available in v12.2 when using language key with country in site config added
Actions #13

Updated by Georg Ringer about 1 year ago

  • Related to Bug #100255: Language of backend user influence FE translations added
Actions

Also available in: Atom PDF