How to replace data = TSFE:sys_language_uid in TYPO3 9 with aspects

Viewed 1917

We've had a typoscript configuration to tell the CSS in which language we are, adding a class into the body tag with a classnames language-x.

Since nothing seems to be documented about how to do this in Typoscript, I haven't tried much to solve this yet.

To do so, we used this typoscript:

// Language
    30 = TEXT
    30 {
        data = TSFE:sys_language_uid
        noTrimWrap = | language-||
    }

This now raises a E_USER_DEPRECATED:

Property $TSFE->sys_language_uid is not in use anymore as this information is now stored within the language aspect

Thanks in advance. Regards Thomi

3 Answers

Since TYPO3 9.5.3 it's also possible to access the current site language configuration with TypoScript Setup:

page.10 = TEXT
page.10.data = siteLanguage:navigationTitle
page.10.wrap = This is the title of the current site language: |

or

page.10 = TEXT
page.10.dataWrap = The current site language direction is {siteLanguage:direction}

See https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5.x/Feature-86973-TypoScriptGetTextPropertySiteLanguage.html for the detailed documentation about the functionality.

@josef-glatz as you suggested, I think this works too.

In Thomi's case, I suggest using:

// Language
    30 = TEXT
    30 {
        data = sitelanguage:languageId
        noTrimWrap = | language-||
    }

IMPORTANT NOTE: This is only available since TYPO3 9.5.4, since Georg Ringer only fixed the issue on 28.12.2018.

Looking at the documentation:

https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/SiteHandling/UseSiteInTypoScript.html

https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/SiteHandling/UseSiteInConditions.html#sitehandling-inconditions

I think you can use a condition like:

[siteLanguage("typo3Language") == "it"]
  page.bodyTag = <body class="language-it">
[global]

Please take note that TYPO3 9.5 already puts the current language in the <html> tag, like: <html lang="it">

So you could use an attribute selector (very well supported) in your css:

html[lang="it"]{
/*css code here*/
}
Related