Search code examples
symfonysonata-admin

How to get the current locale in SonataAdmin


I'm wondering how to get the current locale in a SonataAdmin Admin class. I know that i could pass for example the requestStack as argument of the admin service but i m wondering if sonata admin provide a method to directly access the current locale.


Solution

  • You already have access to the request (\Symfony\Component\HttpFoundation\Request).

    https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Admin/AbstractAdmin.php#L2225

    So $this->request->getLocale() would do the trick.