我有一個關於ZF2翻譯器的問題,在特定情況下,在用戶點擊標誌或菜單鏈接時,可以更改語言鏈接。zf2動態更改語言
在我的應用程序/配置/ module.config.php我有這樣的代碼:
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
),
),
,我的路線是:
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:lang[/:action]]',
'constraints' => array(
'lang' => '[a-zA-Z]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
在我的應用程序/ Module.php我設置上引導代碼:
public function onBootstrap(MvcEvent $e)
{
$sm = $e->getApplication()->getServiceManager();
$router = $sm->get('router');
$request = $sm->get('request');
$matchedRoute = $router->match($request);
$params = $matchedRoute->getParams();
if(isset($params['lang']) && $params['lang'] !== '') {
$translator = $e->getApplication()->getServiceManager()->get('translator');
//or
//$translator = $e->getApplication()->getServiceManager()->get('MvcTranslator');
if($params['lang'] == 'en') {
$translator->setLocale('en_US');
}
}
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
現在我的路線http://www.xxxx.com/it/index或http://www.xxxx.com/it/company,但我不能創建林k在我看來,在我的應用程序中更改語言...
我該如何繼續?
感謝
感謝你的回答......我用這種方法甲階酚醛樹脂是: [如何傳遞變量在ZF2全球layout.phtml] [1] [1]:HTTP:/ /stackoverflow.com/questions/18439364/how-to-pass-variables-to-layout-phtml-globally-in-zf2/18549487#18549487 – 2014-11-08 17:57:09