我需要獲取請求語言環境代碼的幫助。使應用程序區域知道(從URL獲取語言環境)
我的理論是在URL中定義的語言環境,因爲這樣的:
'http://localhost/en/services/web
爲區域en(英語)
OR
'http://localhost/fr/services/web
爲locale fr(法語)
and then extract the locale from the URL and have the routes still work
的值將在更換it
的$lang
可變
這是我的當前的Application Module Class
內部代碼:
public function onBootstrap(MvcEvent $e)
{
$lang = 'it'; // this needs to reflect current request locale instead
$request = $e->getApplication()->getServiceManager()->get('Request');
$translator = $e->getApplication()->getServiceManager()->get('MvcTranslator');
$translator->addTranslationFile("phparray",Pluto::path('language',"$lang.php"));
$viewHelperManager = $e->getApplication()->getServiceManager()->get('ViewHelperManager');
$viewHelperManager->get('translate')->setTranslator($translator);
}
My solution would be to have the variable $lang populated with the request locale
並且剩餘的URL部分相關的路由
我想這些也會對我的路由進行一些修改。