my Request in TYPO3 10.4 with the tx_seo is for only two Lang: de-CH and en-US like this:
<link rel="alternate" hreflang="de-CH" href="https://www.example.org/produkte/test-schiene"/>
<link rel="alternate" hreflang="de-DE" href="https://www.example.org/produkte/test-schiene"/>
<link rel="alternate" hreflang="de-AT" href="https://www.example.org/produkte/test-schiene"/>
<link rel="alternate" hreflang="en-US" href="https://www.example.org/en/products/test-rail"/>
<link rel="alternate" hreflang="x-default" href="https://www.example.org/en/products/test-rail"/>
I have in the Backend only the 2 Language: de-CH = 0 / en-US = 1
My first thought was, the site config.yaml like this (de-DE or de-AT take the lang-id: 0 from de-CH):
languages:
-
title: 'Deutsch (CH)'
enabled: true
base: /
typo3Language: de
locale: de_CH.utf8
iso-639-1: de
websiteTitle: 'test'
navigationTitle: DE
hreflang: de-CH
direction: ''
flag: ch
languageId: 0
-
title: 'Deutsch (DE)'
enabled: true
base: /
typo3Language: de
locale: de_DE.utf8
iso-639-1: de
websiteTitle: 'test'
navigationTitle: DE
hreflang: de-DE
direction: ''
flag: de
languageId: 0
-
title: Englisch
enabled: true
base: /en/
typo3Language: default
locale: en_US.utf8
iso-639-1: en
websiteTitle: 'test'
navigationTitle: EN
hreflang: en-US
direction: ''
flag: en-us-gb
languageId: 1
fallbackType: strict
fallbacks: ''
But it dont work, the HTML Output is this:
<link rel="alternate" hreflang="de-DE" href="https://www.example.org/produkte/test-schiene"/>
<link rel="alternate" hreflang="en-US" href="https://www.example.org/en/products/test-rail"/>
<link rel="alternate" hreflang="x-default" href="https://www.example.org/produkte/test-schiene"/>
There overright the de-CH Language with the de-DE config.
3
Answers
The "default" hreflang from the Ext: tx_seo / site-config take the BE Language. And the other hreflang (DE-DE, DE-AT), i creating this with typoscript.
i don't know if this is the best way to implement?
A different translation should have a unique language id! It looks like you would like to use a "generic" German language and not a country specific variant. But if you just have one generic German version you should decide if you are talking swiss German or german German. And use it accordingly.
If your texts are in swiss German its bad to claim they are German German
Google says the following about Supported language/region codes in hreflang
So if you have only one German page, which is identical for all German-speaking users (and that’s how I understand your request), then it is sufficient to specify "de" as hreflang. There is no need to specify a region additionally.
If you still want to change the output of the HrefLang links, TYPO3 offers since version 10.3 the ModifyHrefLangTagsEvent event with which exactly that is possible.
In your case it could look like this (assuming your HrefLang that TYPO3 generates is for de-CH):
In
EXT:my_extension/Configuration/Services.yaml
and in
EXT:my_extension/Classes/HrefLang/EventListener/OwnHrefLang.php
I hope the answer is helpful for you. 🙂