Project

General

Profile

Actions

Bug #102178

open

Html lang field wrong

Added by Juraj Sulek about 1 year ago. Updated 15 days ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
SEO
Target version:
-
Start date:
2023-10-16
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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'.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Task #101160: Keep hreflang property in site configurationClosedBenni Mack2023-06-23

Actions
Actions #1

Updated by Chris Müller about 1 year 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

Actions #2

Updated by Torben Hansen 8 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.

Actions #3

Updated by Christoph Lehmann 8 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

Actions #4

Updated by Nikita Hovratov 5 months ago

  • Related to Task #101160: Keep hreflang property in site configuration added
Actions #5

Updated by Timo Poppinga 5 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:

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.

Actions #6

Updated by Gerrit Code Review 5 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

Actions #7

Updated by Gerrit Code Review 5 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

Actions #8

Updated by Gerrit Code Review 4 months 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

Actions #9

Updated by Garvin Hicking 4 months ago

  • Assignee set to Garvin Hicking

We'll add the example change to the docs, the one suggested by Christoph Lehmann, thanks!

Actions #10

Updated by Garvin Hicking 2 months ago

  • Status changed from Under Review to Closed
Actions #11

Updated by Gerrit Code Review about 1 month ago

  • Status changed from Closed to Under Review

Patch set 4 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

Actions #12

Updated by Ingo Fabbri 15 days ago

Torben Hansen wrote in #note-2:

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.

This actually a bug. Or at least an undocumented breaking change in v12.

Actions #13

Updated by Ingo Fabbri 15 days ago · Edited

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.

Actions #14

Updated by Garvin Hicking 15 days ago

Sadly the docs PR has stalled too. Uncertain on how to provide an alternative.

Actions #15

Updated by Ingo Fabbri 15 days ago

The workaround using config.htmlTag_stdWrap.override is not going to work.

Someone decided to hack some unintended behaviour into content object renderer:

https://github.com/TYPO3/typo3/blob/v13.4.0/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php#L4057

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?

See https://github.com/TYPO3/typo3/blob/v13.4.0/typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php#L249

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?

Actions #16

Updated by Ingo Fabbri 15 days ago · Edited

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?

Actions #17

Updated by Garvin Hicking 15 days ago

Please respect https://typo3.org/community/values/code-of-conduct

Thank you for your contribution.

Actions #18

Updated by Georg Ringer 15 days ago

  • Assignee deleted (Garvin Hicking)
Actions #19

Updated by Ingo Fabbri 15 days ago

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.

Actions #20

Updated by Benni Mack 15 days ago

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?

Actions #21

Updated by Georg Ringer 15 days ago

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

Actions #22

Updated by Ingo Fabbri 15 days ago

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.

Actions

Also available in: Atom PDF