multilingualtypo3-7.6.xlanguage-switching

TYPO3: How can I redirect to the translated homepage of a non translated page?


I have created a multilanguage TYPO3 site with the following languages:

  1. german (default)
  2. english
  3. spanish

There are no translations for all pages. For example I have ten pages in german and ten translated pages in english, but only four translated pages in spanish, but the language switcher is available on all sites. So if someone moves to one of the six pages which are not available in spanish and try to use the language switcher he will get the following error message:

Page Not Found
Reason: Page is not available in the requested language (strict).

This isn't really nice and I think a better solution is to redirect the user to the spanish homepage if there is no spanish translation of a specific page, but how can I do something like this?

My current language config looks like the following:

config {
    ...
    sys_language_uid = 0
    language = de
    htmlTag_langKey = de-DE
    locale_all = de_DE
    sys_language_mode = strict
}

[globalVar = GP:L = 1]
config {
    sys_language_uid = 1
    language = en
    htmlTag_langKey = en
    locale_all = en_GB
    linkVars = L(1)
}
[global]

[globalVar = GP:L = 2]
config {
    sys_language_uid = 2
    language = es
    htmlTag_langKey = es
    locale_all = es
    linkVars = L(2)
}
[global]

And my language switcher looks like this:

obj.languageSwitcher = HMENU
obj.languageSwitcher {

    special = language
    special.value = 0,1,2
    special.normalWhenNoLanguage = 0

    1 = TMENU
    1 {
        NO = 1
        NO {
            doNotLinkIt = 1
            stdWrap {
                override = DE || EN || ES
                typolink {
                    parameter.data = page:uid
                    additionalParams = &L=0 || &L=1 || &L=2
                }
                outerWrap = <li>|</li>
            }
        }

        ACT < .NO
        ACT {
            stdWrap.typolink >
            stdWrap.outerWrap = <li class="active">|</li>
        }

        USERDEF1 < .NO
        USERDEF1 {
            stdWrap.typolink >
        }
    }
 }

As you can see I currently have defined a USERDEF1 which removes the link from my language switcher if there is no spanish version of the current site, but I still want to redirect the user to the homepage of the spanish version. Do you have any suggestions?


Solution

  • instead of removing the link you should change the target:

    USERDEF1 < .NO
    USERDEF1.stdWrap.typolink {
      parameter.data >
      parameter = 123           <- use your homepage id
    }