src/Controller/LocaleController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use App\Service\LocaleService;
  5. class LocaleController extends BackendBaseController
  6. {
  7.     private $_localeService;
  8.     
  9.     public function __construct(LocaleService $localeService null)
  10.     {
  11.         $this->_localeService $localeService;
  12.     }
  13.     public function changeLocale($locale)
  14.     {
  15.         $this->_localeService->setLocale($locale);
  16.         return $this->returnToPreviousPage();
  17.     }
  18.     
  19.     public function languageWidget()
  20.     {
  21.         $selectedLocale $this->_localeService->getLocale();
  22.         $locales = array();
  23.         foreach($this->_localeService->getAvailableLocales() as $locale)
  24.             $locales[$locale] = $this->_localeService->getLocaleName($locale);
  25.         if (count($locales) <= 1)
  26.             return new Response();
  27.         
  28.         return $this->render('locale/languageWidget.html.twig', array(
  29.             'locales' => $locales,
  30.             'selectedLocale' => $selectedLocale
  31.         ));
  32.     }    
  33. }