How to include current locale like en, tr, ... in url. you can see like of this in symfony or Joomla. when use enter to this url: http://test.com this automatically convert to http://test.com/en I want to include current locale in url and recognize it and change the website locale.
in your Module.php file :
public function onBootstrap(MvcEvent $e)
{
$em = StaticEventManager::getInstance();
$em->attach('Zend\Mvc\Application', MvcEvent::EVENT_ROUTE, array($this, 'onRoute'),
}
public function onRoute(MvcEvent $e)
{
$routeLang = $e->getRouteMatch()->getParam('lang', false);
if(!$routeLang)
$e->getRouter()->setDefaultParam('lang', \Locale::getDefault());
}
and your main route config :
'app' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:lang]',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
'constraints' => array(
'lang' => '[a-z]{0,2}',
),
),
),
all the other routes should be a child of this route.