skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.

    page.headerData {
        900 = COA
        900 {
            10 = TEXT
            10 {
                typolink {
                    parameter.data = page:uid
                    additionalParams = &L=0
                    useCacheHash = 1
                    # add all get parameters from the current URL
                    addQueryString = 1
                    returnLast = url
                    forceAbsoluteUrl = 1
                }
    
                wrap = <link rel="alternate" hreflang="de-DE" href="|" />
    
                append = TEXT
                append.char = 10
            }
            
            20 = TEXT
            20 {
                typolink {
                    parameter.data = page:uid
                    additionalParams = &L=0
                    useCacheHash = 1
                    # add all get parameters from the current URL
                    addQueryString = 1
                    returnLast = url
                    forceAbsoluteUrl = 1
                }
    
                wrap = <link rel="alternate" hreflang="de-AT" href="|" />
    
                append = TEXT
                append.char = 10
            }
        }
    }
    

    i don't know if this is the best way to implement?


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

    Login or Signup to reply.
  3. Google says the following about Supported language/region codes in hreflang

    Supported language/region codes The value of the hreflang attribute
    identifies the language (in ISO 639-1 format) and optionally a region
    (in ISO 3166-1 Alpha 2 format) of an alternate URL. If there’s only
    one code specified, Google assumes the code to be a language code. The
    language doesn’t need to be related to the region. For example:

    • de: German language content, independent of region
    • en-GB: English language content, for GB users
    • de-ES: German language content, for users in Spain

    Warning: Don’t specify a country code by itself. Google
    doesn’t automatically derive the language from the country code. To
    simplify your labeling, you can specify a language code by itself. For
    example:

    • be: Belarusian language, independent of region (Google
      doesn’t understand this to be Belgium)

    To restrict the page to a
    specific region, specify the country code after the language. For
    example:

    • nl-be: Dutch for users in Belgium
    • fr-be: French for users in Belgium

    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

    services:
        VendorMyExtensionHrefLangEventListenerOwnHrefLang:
            tags:
              - name: event.listener
                identifier: 'my-ext/ownHrefLang'
                after: 'typo3-seo/hreflangGenerator'
                event: TYPO3CMSFrontendEventModifyHrefLangTagsEvent
    

    and in EXT:my_extension/Classes/HrefLang/EventListener/OwnHrefLang.php

    namespace VendorMyExtensionHrefLangEventListener;
    
    use TYPO3CMSFrontendEventModifyHrefLangTagsEvent;
    
    class OwnHrefLang
    {
       public function __invoke(ModifyHrefLangTagsEvent $event): void
       {
          $hrefLangs = $event->getHrefLangs();
          $request = $event->getRequest();
    
          $deHrefLang = $hrefLangs['de-CH'];
          $event->addHrefLang('de-DE', $deHrefLang);
          $event->addHrefLang('de-AT', $deHrefLang);
        }
    }
    

    I hope the answer is helpful for you. 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search