I am new to Zend framework 3 and was trying to translate the routes and i have partially succeeded.I am able to translate the main route and redirect it to the required location but for child routes the translation works but the redirection doesn't. can you please help me, my code is below.
module.config.php
'router' => [
'router_class' => TranslatorAwareTreeRouteStack::class,
'routes' => [
'setting' => [
'type' => Segment::class,
'options' => [
'route' => '/{locale}/{setting}',
'defaults' => [
'locale' => 'de',
'controller' => Controller\SettingController::class,
'action' => 'index',
],
],
'may_terminate'=>true,
'child_routes' =>[
'add' =>[
'type' =>'Segment',
'options' =>[
'route' =>'/{add}',
'defaults'=> [
'controller' => Controller\SettingController::class,
'action' => 'add',
],
],
],
],
],
],
],
Module.php
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$language_session = new Container('language');
if(!$language_session->offsetExists('lang')){
$language = 'de_DE';
} else{
$language = $language_session->lang.'_'.strtoupper($language_session->lang);
}
$translator = $e->getApplication()->getServiceManager()->get('translator');
$translator->setLocale($language);
$translator->addTranslationFile('phparray', __DIR__.'/language/'.$language.'.php', 'default',$language);
$app = $e->getTarget();
$app->getEventManager()->attach('route', array($this, 'onPreRoute'), 100);
}
public function onPreRoute($e)
{
$app = $e->getTarget();
$serviceManager = $app->getServiceManager();
$serviceManager->get('router')->setTranslator($serviceManager->get('translator'));
}
And my language file de_De.php
return array(
'locale' => 'de',
'setting' => 'Einstellung',
'add' => 'hinzufügen',
);
As per my above code i am able to redirect to Settings controller with the route "language.devgrafioffshore.com/de/Einstellung"
But not able to redirect to language.devgrafioffshore.com/de/Einstellung/hinzufügen which should redirect me to add action but i get
The requested URL could not be matched by routing.
Thank you in advance. Bye!