Bug #88545
closedEpic #89797: HrefLang / Canonical issues
Behaviour canonical link and HTML lang tag in language overlay
0%
Description
If you on a non-translated alternative language page and the fallback language page is shown, the HTML lang tag provides the wrong language code. It provides the code of the chosen language but it what is actually should provide is the code of the overlay language. For example if you are on a non-translated EN page the fallback language DE is shown. In this case the HTML lang tag should be DE but and not EN.
Second, the canonical link points to the path of the EN page like /en/blablabla which delivers the same content like /de/blablabla which is duplicated content. To solve this problem the canonical link of the non-translated page should point to the URL of the fallback/original page.
TYPO3 version: 9.5.7
Files
Updated by Richard Haeser over 5 years ago
- Status changed from New to Needs Feedback
Hi Altan,
Thanks for your report. For my information. How is your setup and situation? I just tried and could only get this (when:
- Language mode is fallback
- Default language is set as fallback
- There is a page record for default language and for alternative language
- Content in default language and no content in alternative language
So we have a page record but no content for that page. You can set all page properties of the alternative language. You can even decide that you have content for specific colPosses, but not for all. So only empty columns will have a fallback. It is very hard to decide which language code and canonical you need to set in those situations.
How do you see this? When do we set the canonical and language to the fallback language?
Updated by Richard Haeser almost 5 years ago
- Related to Bug #89462: hreflang missing for languages with fallbackType: fallback added
Updated by Richard Haeser almost 5 years ago
- Related to Bug #88020: inconsistencies in hreflang output added
Updated by Susanne Moog almost 5 years ago
- Sprint Focus set to On Location Sprint
Updated by Benjamin Serfhos over 4 years ago
- File ext_localconf.php ext_localconf.php added
- File LanguageFallbackCanonicalGenerator.php LanguageFallbackCanonicalGenerator.php added
I locally fixed this in the beforeGeneratingCanonical signal using the following code in the attached zip.
This function checks if the displayed language content differs from the selected language. If so, writes the canonical url.
It could be directly in CanonicalGenerator as:
/** * @param string $href * @return array */ public function checkForActiveLanguageFallback(string &$href): array { $languageId = $this->languageAspect->getId(); if ($languageId > 0 && $this->languageAspect->getContentId() !== $languageId) { return $this->typoScriptFrontendController->cObj->typoLink_URL([ 'parameter' => $this->typoScriptFrontendController->id . ',' . $this->typoScriptFrontendController->type, 'forceAbsoluteUrl' => true, 'additionalParams' => '&L=' . $this->languageAspect->getContentId(), 'addQueryString' => true, 'addQueryString.' => [ 'method' => 'GET', 'exclude' => implode( ',', CanonicalizationUtility::getParamsToExcludeForCanonicalizedUrl( (int)$this->typoScriptFrontendController->id, (array)$GLOBALS['TYPO3_CONF_VARS']['FE']['additionalCanonicalizedUrlParameters'] ) ), ], ]); } return ''; }
Updated by Richard Haeser almost 4 years ago
- Status changed from Needs Feedback to Closed
With https://review.typo3.org/c/Packages/TYPO3.CMS/+/67574 a hreflang tag is rendered for fallback languages even when no page record is translated. This makes sure those pages are not marked as duplicate content. This way you don't have nasty conditions to check if a page has translated content on it etc. If you want to alter the defined hreflang tags, you can use the ModifyHrefLangTagsEvent. See https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Hooks/Events/Frontend/ModifyHrefLangTagsEvent.html for more information in 10.4. In version 9, you can disable the automatic hreflang tag generation and use your own implementation. For 9.5 you can find more information on https://docs.typo3.org/c/typo3/cms-seo/9.5/en-us/Configuration/Index.html#hreflang-tags