I have a route which specifies a language :lang here (Zend Framework 3):
'contact' => [
'type' => Segment::class,
'options' => [
'route' => '/:lang/hello',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'contact',
'lang' => 'en'
]
],
],
when i go to the webpage http://localhost/pp/public/it/hello it stores the it value into the lang segment.
The problem is on my navigation it says for the other areas as shown:
http://localhost/pp/public/en/services
should have been
http://localhost/pp/public/it/services
Is there a reason why the Zend\Navigation is not using the value it instead of the default value en for the lang parameter of the route assembly
As per Sven Buis comment, you can manually add the current value to every url helper call, but that would probably not be the best way as it means adding code pretty much everywhere for a single purpose.
Another solution is to simply use the last parameter of the url view helper that allows to reuse the current route parameter (set it to true, default is false). I don't like this solution either, because you can have edge cases where all the default haven't been redefined, and that may break your code in places you would not expect.
You can have a look at the approach used in https://github.com/juriansluiman/SlmLocale (only works in ZF2 so far, I haven't had any time to finish my PR for ZF3). It uses the event system to hook up in the dispatch loop and set your language setting somewhere in there.