Getting locale for current request


I am trying to create a multilingual website in Pimcore 5. How do I determine the locale of the current request?

According to the documentation I can use $request->getLocale() in a controller. However., when I do this I get the following exception:

 Trying to set unknown property "locale"

The URL I am requesting points to a document which has the language English (en) set. So I would expect to get an string/object for that.


namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;

class FrontendController extends \Pimcore\Controller\FrontendController {

	protected $request;
	protected $site;
	public function onKernelController(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) {

		if(\Pimcore\Model\Site::isSiteRequest()) {
			$this->site = \Pimcore\Model\Site::getCurrentSite();

		$this->request = $event->getRequest();
		$this->locale = $this->request->getLocale();



I found the problem. Apparently the class variable $this->locale is already used. Using another name works.