Bug #102178
openHtml lang field wrong
0%
Description
the property hreflang was removed from config.yaml in the site configuration.
Now in the vendor/typo3/cms-frontend/Classes/Http/RequestHandler.php this code is used:
$htmlTagAttributes[$docType->isXmlCompliant() ? 'xml:lang' : 'lang'] = $siteLanguage->getLocale()->getLanguageCode();
which produces <html lang="en" for the locale: en_GB.UTF-8
should it not be
$htmlTagAttributes[$docType->isXmlCompliant() ? 'xml:lang' : 'lang'] = $siteLanguage->getLocale()->getName();
in order to get <html lang="en-GB"
because the 'hyphens: auto;' behavior differs for <html lang="en" and for <html lang="en-GB"
When set to 'en', the string 'vegan' is split as 'veg-an', while for 'en-GB', it is correctly split as 've-gan'.
Updated by Chris Müller 10 months ago
- Status changed from New to Needs Feedback
You can still use hreflang attribute in the site configuration. This was changed in this commit and added to a 12.4.x release:
https://review.typo3.org/c/Packages/TYPO3.CMS/+/79488
See also the docs about it:
https://docs.typo3.org/m/typo3/reference-coreapi/12.4/en-us/ApiOverview/SiteHandling/AddLanguages.html#cmdoption-arg-hreflang
Updated by Torben Hansen 5 months ago
A little note here: The hreflang
site setting is not used for HTML lang
attribute any more (see commit https://review.typo3.org/c/Packages/TYPO3.CMS/+/79488), so basically this is no bug but expected behavior.
Updated by Christoph Lehmann 4 months ago
Possible solution to add country part to the lang attribute:
config.htmlTag_stdWrap.override = <html lang="{siteLanguage:hreflang}"> config.htmlTag_stdWrap.override.insertData = 1
Updated by Nikita Hovratov about 2 months ago
- Related to Task #101160: Keep hreflang property in site configuration added
Updated by Timo Poppinga about 2 months ago · Edited
According to RFC https://datatracker.ietf.org/doc/html/rfc5646, the html lang attribute can have more specific information. It would be important to specify the country, e.g. de-CH.
The more specific information is relevant for:
- Search engines
- Screen reader (realy important for accessibility btw mandatory from 2015 in EU https://ec.europa.eu/social/main.jsp?catId=1202)
- Hyphenation
In particular, the country region must be specified.
For example, the W3C sets <html lang="pt-br"> correctly:
https://www.w3.org/International/questions/qa-html-language-declarations.pt-br.html
My expectation is that the lang attribute corresponds to the set hreflink of the page configuration. Fallback is the current language code.
Updated by Gerrit Code Review about 2 months ago
- Status changed from Needs Feedback 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/+/85049
Updated by Gerrit Code Review about 2 months 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/+/85049
Updated by Gerrit Code Review 15 days ago
Patch set 3 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/+/85049
Updated by Garvin Hicking 13 days ago
- Assignee set to Garvin Hicking
We'll add the example change to the docs, the one suggested by Christoph Lehmann, thanks!