<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use App\Service\LocaleService;
class LocaleController extends BackendBaseController
{
private $_localeService;
public function __construct(LocaleService $localeService = null)
{
$this->_localeService = $localeService;
}
public function changeLocale($locale)
{
$this->_localeService->setLocale($locale);
return $this->returnToPreviousPage();
}
public function languageWidget()
{
$selectedLocale = $this->_localeService->getLocale();
$locales = array();
foreach($this->_localeService->getAvailableLocales() as $locale)
$locales[$locale] = $this->_localeService->getLocaleName($locale);
if (count($locales) <= 1)
return new Response();
return $this->render('locale/languageWidget.html.twig', array(
'locales' => $locales,
'selectedLocale' => $selectedLocale
));
}
}