This week a customer asked me to add a multilanguage switch to his TYPO3 website. No problem, that's easy to realize because I am using such a switch for years now on www.weltcafe-dresden.de.
After half an hour, the switch was working but in the meantime I read in TSref (TypoScript Reference) about the special language menu support of the HMENU (Hierarchical Menu) object. Then I played around another hour to get this working. Here is my solution. Just, to find it for the next project:
temp.language = HMENU
temp.language.special = language
temp.language.special.value = 0,1,2
temp.language {
1 = TMENU
1 {
wrap = <ul class="toplangmenu">|</ul>
noBlur = 1
NO = 1
NO {
#wrapItemAndSub = <li class="">|</li>
before =
after = <li>/</li> |*| <li>/</li> |*|
linkWrap = <li>|</li>
# wrap the page title! otherways you see the current page title instead of the language.
stdWrap.override = [deutsch] || [english] || [francais]
}
# active language
ACT < .NO
ACT {
# doNotLinkIt = 1
linkWrap = <li class="active">|</li>
}
# NO + Translation doesn't exist
USERDEF1 < .NO
# USERDEF1.doNotLinkIt = 1
# ACT + Translation doesn't exist
USERDEF2 < .ACT
# USERDEF2.doNotLinkIt = 1
}
}
There are four states of this menu:
So you can avoid the language switch on pages where you have no translations for example with doNotLinkIt = 1.
Don't forget to set some useful and necessary config options in your TSsetup:
// Language Switch
config {
linkVars = L
sys_language_uid = 0
language = de
#Language for the proper "xml:lang" and "lang" value in -Tag
htmlTag_langKey = de
locale_all = de_DE.UTF-8
sys_language_mode = content_fallback
sys_language_overlay = 1
}
[globalVar = GP:L = 1]
config {
linkVars = L
sys_language_uid = 1
language = en
htmlTag_langKey = en
locale_all = en_GB.UTF-8
}
[global]
By chance, I found another setting which is not important but nice for the backend user. Usually you don't create the Default website language (this is done on your root page). So everywhere you may select "DEFAULT" (which is in my case German) and "English" or whatever language you added.
To overwrite this DEFAULT label with e.g. Deutsch, do the following on the TS page setup of your root page:
mod.SHARED {
defaultLanguageFlag=Deutsch
defaultLanguageLabel=de.gif
}
Your comment