MatchedLanguage Aspect¶
The results of the language matching in the middleware is stored in an Aspect,
using the TYPO3 Context API. It contains the
matched language as SiteLanguage
object (see
PHP API: accessing site configuration), or null
if there was no match.
The MatchedLanguage Aspect accepts two kinds of properties:
- Results of the language matching process.
- Some properties of the
SiteLanguage
object. That’s why a matched language must be present (as long as the properties are accessed through the official API [$context->getPropertyFromAspect()
], there are no errors to expect if noSiteLanguage
object exists).
Property | Description | Matched language required |
---|---|---|
exists |
Is true when a matched language exists |
No |
equalsCurrentLanguage |
Is true when the matched language equals the
current SiteLanguage |
No |
canBeRequested |
Is true when the current page can be requested
in the matchedLanguage |
No |
id |
SiteLanguage::getLanguageId() |
Yes |
hreflang |
SiteLanguage::getHreflang() |
Yes |
twoLetterIsoCode |
SiteLanguage::getTwoLetterIsoCode() |
Yes |
title |
SiteLanguage::getTitle() |
Yes |
navigationTitle |
SiteLanguage::getNavigationTitle() |
Yes |
PHP Example¶
$context = GeneralUtility::makeInstance(Context::class);
// Check if a link to another language version of the page should be presented
$presentLinkToOtherLanguage = $context->getPropertyFromAspect('matchedLanguage', 'canBeRequested')
&& !$context->getPropertyFromAspect('matchedLanguage', 'equalsCurrentLanguage');
if ($presentLinkToOtherLanguage) {
// Retrieve the navigationTitle of the matched language
$linkText = $context->getPropertyFromAspect('matchedLanguage', 'navigationTitle');
}