zend-router
zend-router copied to clipboard
Multilingual site in ZF3
When i set the locale parameter to another value than the default value that has been defined in module.config.php, the routing does not take this into account and uses the default value of locale instead.
Code to reproduce the issue
route definition of module.config.php:
'router' => [
'router_class' => TranslatorAwareTreeRouteStack::class,
'routes' => [
'home' => [
'type' => Segment::class,
'options' => [
'route' => '/',
'constraints' => [
'amp' => 'amp'
],
'defaults' => [
'locale' => 'nl',
'controller' => WebsiteController::class,
'action' => 'index',
],
],
],
'website' => [
'type' => Segment::class,
'options' => [
'route' => '/:locale/{home}[/:amp]',
'constraints' => [
'amp' => 'amp'
],
'defaults' => [
'locale' => 'nl',
'controller' => WebsiteController::class,
'action' => 'index',
],
],
],
'faq' => [
'type' => Segment::class,
'options' => [
'route' => '/:locale/{faq}[/:amp]',
'constraints' => [
'amp' => 'amp'
],
'defaults' => [
'locale' => 'nl',
'controller' => WebsiteController::class,
'action' => 'faq',
],
],
],
layout in which you can choose another language: website.phml I have hard coded the value to 'en':
<li>
<a href="<?= $this->url('home', ['locale' => 'en']); ?>"<?= ($this->plugin('translate')->getTranslator()->getLocale() == 'en') ? ' class="active"' : null; ?>>
<img src="<?= $this->basepath($language['data'][11]); ?>" alt="<?= $language['data'][3]; ?>" width="54" height="37" />
</a>
</li>
Expected results
I should expect that ZF knows that locale should be set to 'en' without having to send the 'locale' parameter with every link you create on the website. When I go to the faq, i would expect that te site goes to http://mydomain.com/en/faq
Actual results
When I switch to en, the routing uses the default value 'nl' instead So when I go to the faq now, the site goes to http://mydomain.com/nl/faq , when I have switched the language to en.
@willemserik check https://github.com/basz/SlmLocale develop, maybe this help you
This repository has been closed and moved to laminas/laminas-router; a new issue has been opened at https://github.com/laminas/laminas-router/issues/2.