Laravel/Add locale selector

From Aimeos documentation

Laravel
Other languages:
English 100%


2016.x version

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.

Configuration

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 config/shop.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.

If you upgrade from earlier versions, please make sure that your shop configuration (in config/shop.php) contains these lines too:

  1. 'client' => array(
  2. 	'html' => array(
  3. 		'locale' => array(
  4. 			'select' => array(
  5. 				'currency' => array(
  6. 					'param-name' => 'currency',
  7. 				),
  8. 				'language' => array(
  9. 					'param-name' => 'locale',
  10. 				),
  11. 			),
  12. 		),
  13. 	),
  14. ),

Templates

Laravel applications can overwrite the templates of packages by copying a modified version of the template to the resources/views/vendor/aimeos/shop/ directory. This is done automatically during the installation via composer.

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. @section('aimeos_header')
  2.     ...
  3.     <?= $aiheader['locale/select'] ?>
  4. @stop
  5.  
  6. @section('aimeos_head')
  7.     ...
  8.     <?= $aibody['locale/select'] ?>
  9. @stop

Templates that should be modified:

  • account/index.blade.php
  • basket/index.blade.php
  • catalog/detail.blade.php
  • catalog/list.blade.php

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.

Routes

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 config/shop.php:

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

These two 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' => array( 'prefix' => '{locale}', ... ),
  3.     'default' => array( 'prefix' => '{locale}', ... ),
  4.     'confirm' => array( 'prefix' => '{locale}', ... ),
  5.     'update' => array( 'prefix' => '{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.