Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
   eZ Publish 4.x / legacy

eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Skip to end of metadata
Go to start of metadata

Version compatibility

Language switcher in Symfony stack is compatible with eZ Publish 5.3 / 2014.05


A content item can be translated in several languages. Those languages are configured in the system and exposed in SiteAccesses via a prioritized list of languages:


When visiting a Content item, it may be useful to let the user switch from one translation to another, more appropriate to him. This is precisely the goal of the language switcher.

The language switcher relies on the Cross-SiteAccess linking feature to generate links to the content's translation, and on RouteReference feature.


If you install the DemoBundle with at least 2 different languages, you will be able to see the Language Switcher and to test it.



Configuration: explicit translation SiteAccesses

Configuration is not mandatory, but can help to distinguish which SiteAccesses can be considered translation SiteAccesses.



Note: Top prioritized language is always used for as the SiteAccess language reference (e.g. fre-FR for fre SiteAccess in the example above).

If several translation SiteAccesses share the same language reference, the first declared SiteAccess always wins.

Configuration: more complex translation setup

There are some cases where your SiteAccesses share settings (repository, content settings...), but you don't want all of them to share the same translation_siteaccesses setting. This can be the case when you use SiteAccesses for mobile.

Solution is as easy as defining new groups:


Configuration: using implicit related SiteAccesses

If translation_siteaccesses setting is not provided, implicit related SiteAccesses will be used instead. SiteAccesses are considered related if they share:

In a template

To generate a language switch link, you need to generate the RouteReference, with the language parameter. This can easily be done with ez_route() Twig function:

You can also omit the route, in this case, the current route will be used (i.e. switch the current page):

Using sub-requests

When using sub-requests, you lose the context of the master request (e.g. current route, current location...). This is because sub-requests can be displayed separately, with ESI or Hinclude.

If you want to render language switch links in a sub-request with a correct RouteReference, you must pass it as an argument to your sub-controller from the master request.

  • ezpublish.translationSiteAccess( language ) returns the SiteAccess name for provided language (or null if it cannot be found)
  • ezpublish.availableLanguages() returns the list of available languages.

Using PHP

You can easily generate language switch links from PHP too, with the RouteReferenceGenerator service:

You can also retrieve all available languages with the TranslationHelper:






  1. Unknown User (lymathon)


    The last ")" is missing in this line, in the "Using PHP" example :

    $routeRef = $routeRefGenerator->generate( $location, array( 'language' => 'fre-FR' ) );
  2. Unknown User (flovntp)

    Hi all,

    Be careful if you try to display language switcher from a subrequest, you will need to pass current location id (or currentLocation) to your ez_route(), like for preview (cf.  EZP-23222 - LanguageSwitcher does not work in content preview Closed

    something like : 
    {{ render( controller( 'MyBundle:Default:switchLanguage', {'routeRef': ez_route( 'ez_urlalias', { 'locationId': current_location_id } )} ) ) }}