Gislaved
Gislaved

Reputation: 37

ZF3 Get browser Language

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 ?

Upvotes: 0

Views: 499

Answers (2)

Waqar Haider
Waqar Haider

Reputation: 973

In ZF 2 , somewhere in Controller

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

Upvotes: 0

akond
akond

Reputation: 16060

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

or

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

Upvotes: 1

Related Questions