Language menu

Creates a language selector menu.

The special = language type will create menu items based on the current page record but with the language record for each language overlaid if available.

Properties

special.value

special.value

special.value
Type
comma separated list of language UIDs /stdWrap or auto

The number of elements in this list determines the number of menu items. Setting to auto will include all available languages from the current site.

special.normalWhenNoLanguage

special.normalWhenNoLanguage

special.normalWhenNoLanguage
Type
boolean

If set, the button for a language will be rendered as a non- disabled button even if no translation is found for the language.

Example: Create a language menu with pure TypoScript

EXT:site_package/Configuration/TypoScript/Menus/Setup/LanguageMenuLib.typoscript
lib.langMenu = HMENU
lib.langMenu {
    special = language
    special.value = 0,1,2
    wrap = <ul class="langugageMenu">|</ul>
    1 = TMENU
    1 {
        NO = 1
        NO {
            linkWrap = <li>|</li>
            doNotLinkIt = 1
            stdWrap.override = en || de || fr
            stdWrap.typolink {
                parameter.data = page:uid
                additionalParams = &L=0 || &L=1 || &L=2
                addQueryString = 1
                addQueryString.exclude = L,id

            }
        }
        // We are in the current language
        ACT < .NO
        ACT {
            linkWrap = <li class="active">|</li>
        }
        // No translation available
        USERDEF1 < .NO
        USERDEF1 {
            linkWrap = <li class="disabled">|</li>
            stdWrap.typolink >
        }
    }
}
Copied!

Note on item states

When the language of the menu element matches the current language of the page displayed, the state is set to ACT, otherwise NO. However, if a page is not available due to the pages "Localization settings" (which can disable translations) or if no Alternative Page Language record was found (can be disabled with .normalWhenNoLanguage, see below) the state is set to USERDEF1 for non-active items and USERDEF2 for active items. So in total there are four states to create designs for. It is recommended to disable the link on menu items rendered with USERDEF1 and USERDEF2 in this case since they are disabled exactly because a page in that language does not exist and might even issue an error if tried accessed (depending on site configuration).