ZF3 Get browser Language

2019-08-20 00:59发布

There are a several of ways to get the browser language in Zend Framework 3. Can anyone tell me what should be the right way ?

I was thinking about getting the locale and substract the language from it ?

2条回答
三岁会撩人
2楼-- · 2019-08-20 01:32

In ZF 2 , somewhere in Controller

$translator = $this->getServiceLocator()->get('translator');
    $t  = $translator->getLocale();
查看更多
Fickle 薄情
3楼-- · 2019-08-20 01:48
$this->request->getHeader('Accept-Language')->getPrioritized()[0]->getPrimaryTag();

or

$this->request->getHeader('Accept-Language')->getPrioritized()[0]->getLanguage();
查看更多
登录 后发表回答