« July 2011»
M T W T F S S
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

[blog...]

06.07.2011
17:43

TYPO3 Language Switch Using HMENU special.language

Language Switch on the Weltcafe Dresden site
defaultLanguageFlag=Deutsch

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:

  • NO for not selected
  • ACT for active selection
  • USERDEF1 which is the same as NO, but there is no translation found
  • USERDEF2 which is the same as ACT, but there is no translation found

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
}

 

 

  •  
  • 0 Comment(s)
  •  

Your comment

Notify me when someone adds another comment to this post

back

[ 07.05.2012 ]