Slim/Add locale selector

From Aimeos documentation

This page contains changes which are not marked for translation.

Other languages:
English 100%

For shops offering multiple languages, currencies or both, Aimeos contains a locale selector component that renders menus of the configured language/currency combinations, so visitors are able to choose their preferred language and/or currency. By default, both will be part of the URL afterwards.

How to add locales for language/currency combinations is described in the user manual.


To make the locale selector available in the templates, you need to add the component name to the page configuration. Replace the relevant settings for the "page" configuration in your ./src/aimeos-settings.php file which these lines:

  1. 'page' => array(
  2. 	'account-index' => array( 'locale/select','account/history','account/favorite','account/watch','basket/mini','catalog/session' ),
  3. 	'basket-index' => array( 'locale/select','basket/standard','basket/related' ),
  4. 	'catalog-detail' => array( 'locale/select','basket/mini','catalog/stage','catalog/detail','catalog/session' ),
  5. 	'catalog-list' => array( 'locale/select','basket/mini','catalog/filter','catalog/stage','catalog/lists' ),
  6. 	// ...
  7. ),

They add the "locale/select" component to the account, basket, catalog detail and catalog list templates where they can be rendered afterwards.


In each page template where the locale selector should be available, you need to add the lines for rendering the header and body section of the locale selector:

  1. {% block aimeos_header %}
  2.     ...
  3.     {{ aiheader['locale/select']|raw }}
  4. {% endblock %}
  6. {% block aimeos_head %}
  7.     ...
  8.     {{ aibody['locale/select']|raw }}
  9. {% endblock %}

Templates that should be modified:

  • Account/index.html.twig
  • Basket/index.html.twig
  • Catalog/detail.html.twig
  • Catalog/list.html.twig

Depending on the section you've added the body of the locale selector to, it will be rendered at different places. For more details about templates, please have a look into the article about adapting pages.


Language and currency ID chosen by the visitor are part of the URL by default, so they are explicit and can be cached (contrary to information based on session data). To make this work, you need to add a route prefix in your ./src/aimeos-settings.php:

  1. 'routes' => array(
  2.     'account' => '/{locale}/{currency}',
  3.     'default' => '/{locale}/{currency}',
  4.     'confirm' => '/{locale}/{currency}',
  5.     'update' => '/{locale}/{currency}',
  6. ),

These lines require that the language ("locale") and currency ID must be part of all URLs besides the "admin" ones. If you only need the language, you should use this instead:

  1. 'routes' => array(
  2.     'account' => '/{locale}',
  3.     'default' => '/{locale}',
  4.     'confirm' => '/{locale}',
  5.     'update' => '/{locale}',
  6. ),

Adapt selector

The locale selector is a normal component with subparts, that can be adapted like any other component. If you e.g. only need a language or currency menu, you can remove the subpart you don't need via the client/html/locale/select/standard/subparts configuration.

Adapting the layout of the locale selector is possible via CSS.