Current

This document is valid for the current version of Plone.

Language selector

by Plone Documentation Team last modified Dec 12, 2009 10:33 PM
Contributors: Mikko Ohtamma, Martin Aspeli, Kamon Ayeva, Israel Saeta Pérez
Plone comes with a language selector viewlet which you often want to customize for your theme or your special language configuration

There exist two different language selector viewlet bases for Plone

  • Viewlet from vanilla Plone
  • Viewlet from LinguaPlone - LinguaPlone has its own language selector which replaces the default Plone selector if LinguaPlone is installed

Making language flags point to different domains

It is often desirable to make the language selector point to a different domains for different languages. For example, search engines get confused by dynamic language switcher and will index switching links, messing up your site search results.

Below is an example where different top level domain links are hard coded to the language selector template:

<tal:language
    tal:define="available view/available;
                languages view/languages;
                showFlags view/showFlags;">


    <ul id="portal-languageselector"
        tal:condition="python:available and len(languages)>=2">
        <tal:language repeat="lang languages">
        <li tal:define="code lang/code;
                        selected lang/selected"
            tal:attributes="class python: selected and 'currentLanguage' or '';">

                <a href=""
                   tal:condition="python:code =='fi'"
                   tal:define="flag lang/flag|nothing;
                               name lang/name"
                   tal:attributes="href string:http://www.twinapex.fi;
                                   title name">
                    <tal:flag condition="python:showFlags and flag">
                        <img
                             width="14"
                             height="11"
                             alt=""
                             tal:attributes="src string:${view/portal_url}${flag};
                                             title python: name;
                                             class python: selected and 'currentItem' or '';" />
                    </tal:flag>
                    <tal:nonflag condition="python:not showFlags or not flag"
                                 replace="name">language name</tal:nonflag>
                </a>

                <a href=""
                   tal:condition="python:code =='en'"
                   tal:define="flag lang/flag|nothing;
                               name lang/name"
                   tal:attributes="href string:http://www.twinapex.com;
                                   title name">
                    <tal:flag condition="python:showFlags and flag">
                        <img
                             width="14"
                             height="11"
                             alt=""
                             tal:attributes="src string:${view/portal_url}${flag};
                                             title python: name;
                                             class python: selected and 'currentItem' or '';" />
                    </tal:flag>
                    <tal:nonflag condition="python:not showFlags or not flag"
                                 replace="name">language name</tal:nonflag>
                </a>&nbsp;

        </li>
        </tal:language>
    </ul>
</tal:language>