ZF3 Get browser Language

爷,独闯天下 提交于 2019-12-24 23:58:57

问题


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 ?


回答1:


$this->request->getHeader('Accept-Language')->getPrioritized()[0]->getPrimaryTag();

or

$this->request->getHeader('Accept-Language')->getPrioritized()[0]->getLanguage();



回答2:


In ZF 2 , somewhere in Controller

$translator = $this->getServiceLocator()->get('translator');
    $t  = $translator->getLocale();


来源:https://stackoverflow.com/questions/46797651/zf3-get-browser-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!