#102178Html lang field wrong
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’.
Reviews 5
- 13.4 91085[BUGFIX] Render hreflang properly in TypoScript getData
- main 86444[BUGFIX] Render hreflang properly in TypoScript getData
- 13.4 90297[BUGFIX] Re-add country code to html lang attribute
- main 85049[BUGFIX] Re-add country code to html lang attribute
- main 79488[TASK] Re-introduce hreflang attribute of site language configuration
Related issues 2
History 2837
Show 812 earlier messages
-
Chris Müller commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2023-10-16T16:20:59+00:00" > 10/16/23, 16:20 </span> -
Torben Hansen commented <span data-processor="relativetime" data-value="2024-03-28T13:55:17+00:00" > 03/28/24, 13:55 </span>
A little note here: The
hreflangsite setting is not used for HTMLlangattribute any more (see commit https://review.typo3.org/c/Packages/TYPO3.CMS/+/79488), so basically this is no bug but expected behavior. -
Christoph Lehmann commented <span data-processor="relativetime" data-value="2024-04-08T15:42:46+00:00" > 04/08/24, 15:42 </span>
Possible solution to add country part to the lang attribute:
config.htmlTag_stdWrap.override = <html lang="{siteLanguage:hreflang}"> config.htmlTag_stdWrap.override.insertData = 1 -
Nikita Hovratov changed Related to #101160 <span data-processor="relativetime" data-value="2024-07-01T14:10:24+00:00" > 07/01/24, 14:10 </span>
-
Timo Poppinga commented <span data-processor="relativetime" data-value="2024-07-01T14:26:51+00:00" > 07/01/24, 14:26 </span>
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"></html>
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.
-
Gerrit Code Review pushed patch set 1 for main to change 85049 status
Needs FeedbackUnder Review <span data-processor="relativetime" data-value="2024-07-01T14:47:30+00:00" > 07/01/24, 14:47 </span> -
Gerrit Code Review pushed patch set 2 for main to change 85049 <span data-processor="relativetime" data-value="2024-07-01T14:49:00+00:00" > 07/01/24, 14:49 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 85049 <span data-processor="relativetime" data-value="2024-08-01T08:02:17+00:00" > 08/01/24, 08:02 </span>
-
Garvin Hicking commented and changed assigned to Garvin Hicking <span data-processor="relativetime" data-value="2024-08-03T08:09:56+00:00" > 08/03/24, 08:09 </span>
We’ll add the example change to the docs, the one suggested by Christoph Lehmann, thanks!
-
Garvin Hicking commented and changed status
Under ReviewClosed <span data-processor="relativetime" data-value="2024-09-15T17:46:24+00:00" > 09/15/24, 17:46 </span> -
Gerrit Code Review pushed patch set 4 for main to change 85049 status
ClosedUnder Review <span data-processor="relativetime" data-value="2024-10-18T13:41:46+00:00" > 10/18/24, 13:41 </span> -
Ingo Fabbri commented <span data-processor="relativetime" data-value="2024-11-06T12:04:46+00:00" > 11/06/24, 12:04 </span>
Torben Hansen wrote in #note-2:
> A little note here: Thehreflangsite setting is not used for HTMLlangattribute any more (see commit https://review.typo3.org/c/Packages/TYPO3.CMS/+/79488), so basically this is no bug but expected behavior.This actually a bug. Or at least an undocumented breaking change in v12.
-
Ingo Fabbri commented <span data-processor="relativetime" data-value="2024-11-06T12:28:00+00:00" > 11/06/24, 12:28 </span>
It’s disheartening to see this bug report lingering unresolved for over a year. From the looks of the linked patchset, it doesn’t seem like a resolution is coming soon. The decision to deprecate the `hreflang` language property has made things unnecessarily complicated, especially since now efforts are focused on “working around” the deprecation. Relying on the locale setting alone feels like a misguided approach.
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2024-11-06T12:51:55+00:00" > 11/06/24, 12:51 </span>
Sadly the docs PR has stalled too. Uncertain on how to provide an alternative.
-
Ingo Fabbri commented <span data-processor="relativetime" data-value="2024-11-06T13:34:35+00:00" > 11/06/24, 13:34 </span>
The workaround using config.htmlTag_stdWrap.override is not going to work.
Someone decided to hack some unintended behaviour into content object renderer:
The relevant part:
case 'sitelanguage': // @todo: Check when/if there are scenarios where attribute 'language' is not yet set in $request. $siteLanguage = $this->getRequest()->getAttribute('language') ?? $this->getRequest()->getAttribute('site')->getDefaultLanguage(); if ($key === 'twoLetterIsoCode') { $key = 'locale:languageCode'; } if ($key === 'hreflang') { $key = 'locale:full'; }If “hreflang” then return some “locale:full”. Seriously – who reviewed that change over at gerrit? This is ridicoulous. SiteLanguage is a class and it has a public getter called getHreflang. One sane person would expect this getter to be called – instead some wonky conditional handling is baked into?
There is something fundamentally wrong in this approach. When was decided that “hreflang” on site-language is the devil and needs to be cast out?
-
Ingo Fabbri commented <span data-processor="relativetime" data-value="2024-11-06T13:38:06+00:00" > 11/06/24, 13:38 </span>
This is a concerning change: https://github.com/TYPO3/typo3/commit/58592d315a121ce795ebb2a918559d091237a6ef
How can a change that most would consider a breaking change be categorized as just a task?
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2024-11-06T13:45:41+00:00" > 11/06/24, 13:45 </span>
Please respect https://typo3.org/community/values/code-of-conduct
Thank you for your contribution.
-
Georg Ringer changed removed the assignee <span data-processor="relativetime" data-value="2024-11-06T13:51:57+00:00" > 11/06/24, 13:51 </span>
-
Ingo Fabbri commented <span data-processor="relativetime" data-value="2024-11-06T14:36:06+00:00" > 11/06/24, 14:36 </span>
Garvin Hicking wrote in #note-17:
> Please respect https://typo3.org/community/values/code-of-conduct
>
> Thank you for your contribution.> Don’t be afraid to be yourself, but be your best. You are a free individual with the right to your own personal views and values.
The challenge is that, while I’m free to express my own opinions, the views of the core developers seem very fixed and set in stone. This makes it difficult to fully embrace the idea of “Don’t be afraid to be yourself, but be your best.” This comes from 20 years of experience with TYPO3.
-
Benni Mack commented <span data-processor="relativetime" data-value="2024-11-06T14:45:05+00:00" > 11/06/24, 14:45 </span>
Hi Ingo,
as this issue has been adressed multiple times already in various issues and places, and I already mentioned this: I did not consider this implication when I deprecated this option, and I am fine with undeprecating this option in v12 and higher. I also have no problem to state this: This was my fault in the first place. My question is: Can you please come up with a patch for v12/v13 so it works as you expect and recommend?
-
Georg Ringer commented <span data-processor="relativetime" data-value="2024-11-06T14:46:08+00:00" > 11/06/24, 14:46 </span>
just my 2c: a lot is not set in stone and helpful input is always welcome but as every one of us got a day job, a life and there still a lot of other issues as well I guess most will just walk away and do something different
-
Ingo Fabbri commented <span data-processor="relativetime" data-value="2024-11-06T15:50:48+00:00" > 11/06/24, 15:50 </span>
Benni Mack wrote in #note-20:
> Hi Ingo,
>
> as this issue has been adressed multiple times already in various issues and places, and I already mentioned this: I did not consider this implication when I deprecated this option, and I am fine with undeprecating this option in v12 and higher. I also have no problem to state this: This was my fault in the first place. My question is: Can you please come up with a patch for v12/v13 so it works as you expect and recommend?I’ll take a closer look and propose a patch. However, the issue I see is that this regression has now been around long enough to be considered accepted behavior. Instead of handling it as a standard bug fix, it may be more appropriate to deprecate it and introduce a breaking change in the next major version. It’s a bit of a tricky situation.
-
Boris von Martens commented <span data-processor="relativetime" data-value="2024-12-21T06:17:21+00:00" > 12/21/24, 06:17 </span>
Not a beauty, but a valid workaround without overriding the whole html tag:
[siteLanguage("languageId") == 0] config.htmlTag.attributes.lang = de-DE [siteLanguage("languageId") == 1] config.htmlTag.attributes.lang = en-DE [siteLanguage("languageId") == 2] config.htmlTag.attributes.lang = de-AT [siteLanguage("languageId") == 3] config.htmlTag.attributes.lang = en-AT [siteLanguage("languageId") == 6] config.htmlTag.attributes.lang = nl-NL [END]Good news is that hreflang setting in the site configuration has been UNdeprecated in https://forge.typo3.org/issues/101160
However, it is currently not working as expected. (see: https://forge.typo3.org/issues/101160#note-10) -
Alexander Opitz commented <span data-processor="relativetime" data-value="2025-03-04T19:40:34+00:00" > 03/04/25, 19:40 </span>
I tried to add a comment on the patch in question, but got an error. As I got hints about this open ticket, I’ll post here what I tried to comment on the patch.
This patch breaks the <html lang=""> Tag. The commit message says: "It is not used within the <html lang="..."> attribute anymore as this was a mis-use in the first place (and now properly using just the language key, see https://www.w3.org/International/questions/qa-html-language-declarations.en.html#attributes") But this is wrong, as given link describes the handling of xml:lang vs lang in the <html> tag. The correct link for the value description is https://www.w3.org/International/questions/qa-html-language-declarations.en.html#langvalues which explains that the value can be "BCP 47" ``BCP 47 incorporates, but goes beyond, the ISO sets of language and country codes.´´ So using only the ISO language code in <html lang=""> is not valid. -
Daniel Siepmann commented <span data-processor="relativetime" data-value="2025-07-24T06:38:04+00:00" > 07/24/25, 06:38 </span>
https://git.typo3.org/typo3/typo3/-/commit/85d2b5b17ce774e3dbbd81d4c8f6c9d81da0b497 already reverted most stuff.
But I don’t get why it moved fromhreflang()to the locale, that way the hreflang is not used anymore: https://git.typo3.org/typo3/typo3/-/commit/85d2b5b17ce774e3dbbd81d4c8f6c9d81da0b497#54510d8d0d1b7ab2ee321107ec61a20d48ed55ad_298_295We added a composer patch to revert this line to full fill the need.
-
Benni Mack commented <span data-processor="relativetime" data-value="2025-07-24T07:29:02+00:00" > 07/24/25, 07:29 </span>
Daniel Siepmann wrote in #note-25:
> https://git.typo3.org/typo3/typo3/-/commit/85d2b5b17ce774e3dbbd81d4c8f6c9d81da0b497 already reverted most stuff.
> But I don’t get why it moved fromhreflang()to the locale, that way the hreflang is not used anymore: https://git.typo3.org/typo3/typo3/-/commit/85d2b5b17ce774e3dbbd81d4c8f6c9d81da0b497#54510d8d0d1b7ab2ee321107ec61a20d48ed55ad_298_295
>
> We added a composer patch to revert this line to full fill the need.my current issue is that our “hreflang” property is used in the <link> attribute, if set. The “lang” attribute for the html tag however is not obious to me what is right. I really have one SEO specialist that says it needs to be something else than the hreflang (e.g. “en-dk” – so it should actually be “en”) and the other SEO specialist says the opposite.
For me this topic is super frustrating… maybe we can find a real official resource that defines what should be included – I only have
- https://html.spec.whatwg.org/multipage/dom.html#attr-lang
- https://www.w3.org/International/questions/qa-html-language-declarations.en.html#attributeson my personal list, no clear definition for me.
-
Daniel Siepmann commented <span data-processor="relativetime" data-value="2025-07-24T13:11:16+00:00" > 07/24/25, 13:11 </span>
I can really understand the frustration and also the confusion with SEO Experts …
Your link only explains when to use which attribute
langvsxml:lang. But we are discussing the value of the attribute. That’s explained in the paragraph above: https://www.w3.org/International/questions/qa-html-language-declarations.en.html#langvalues. This also references https://www.w3.org/International/questions/qa-choosing-language-tags, and I also found https://datatracker.ietf.org/doc/html/rfc5646 which describes the situation as well.But I didn’t invest too much time. We came here because our Frontend JavaScript library reacts to the value for localization. Also, other accessibility resources state that voice over and other things respect the value, e.g. will use different voices/sound files based on American or British English.
It is pretty easy to adjust via a patch, so no pressure from our end. It is probably better to first clearly define the expectation and come up with a final solution instead of changing things over and over again.
My ideas/thoughts:
- Make it configurable / flexible, so everyone can tweak it to the specific needs.
- Specify a priority, e.g. accessibility, RFC, etc. over some SEO aspects.
- Allow to provide a value forhreflangalternative links and one for the HTMLlangattribute. -
Hannes Lau commented <span data-processor="relativetime" data-value="2025-07-24T15:27:18+00:00" > 07/24/25, 15:27 </span>
Regarding the country code in the html lang attribute @benni writes:
> I really have one SEO specialist that says it needs to be something else than the hreflang (e.g. “en-dk” – so it should actually be “en”)
Did the specialist provide any reason for this statement? For screen readers, automated date formatting, translation etc. it is useful to have the country code included in the lang tag. This is also exemplified in the description of this issue. So I wonder what the downside would be if we add the country code to the lang attribute.
Regarding hreflang: If a website has country specific versions (en-UK, en-US, en-CA) it makes sense to include the country codes in the hreflang links. There may be an additional generic en site. https://developers.google.com/search/docs/specialty/international/localized-versions
If there is only one generic english Version, hreflang will be reduced to “en” as well.I suggest to unify the handling of hreflang and html lang again. But I would be curious to hear the reasons against it.
-
Gerrit Code Review pushed patch set 5 for main to change 85049 <span data-processor="relativetime" data-value="2025-07-24T15:32:08+00:00" > 07/24/25, 15:32 </span>
-
Gerrit Code Review pushed patch set 6 for main to change 85049 <span data-processor="relativetime" data-value="2025-07-24T15:32:58+00:00" > 07/24/25, 15:32 </span>
-
Benni Mack commented <span data-processor="relativetime" data-value="2025-07-24T15:33:58+00:00" > 07/24/25, 15:33 </span>
I will ask about the reasons at my next meeting. In the meantime, feel free to vote on the patch.
-
Benni Mack changed Related to #104987 <span data-processor="relativetime" data-value="2025-07-24T15:35:12+00:00" > 07/24/25, 15:35 </span>
-
Gerrit Code Review pushed patch set 7 for main to change 85049 <span data-processor="relativetime" data-value="2025-07-24T16:13:40+00:00" > 07/24/25, 16:13 </span>
-
Gerrit Code Review pushed patch set 8 for main to change 85049 <span data-processor="relativetime" data-value="2025-07-24T17:09:32+00:00" > 07/24/25, 17:09 </span>
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 90297 <span data-processor="relativetime" data-value="2025-08-09T09:21:36+00:00" > 08/09/25, 09:21 </span>
-
Anonymous commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2025-08-09T09:25:08+00:00" > 08/09/25, 09:25 </span>Applied in changeset commit:79e8ce4f92f447c98688a94f6039e7062684cfec.
-
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2025-12-02T14:37:04+00:00" > 12/02/25, 14:37 </span>
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