From cc4301d6279f88f4864222c8f8a17446c47097e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Wed, 14 Sep 2022 16:31:55 +0200 Subject: [PATCH] Allow to use translate controller without sensio/framework-extra-bundle --- Controller/TranslateController.php | 20 +++++++++++++++++--- Resources/config/services.xml | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Controller/TranslateController.php b/Controller/TranslateController.php index 8ce17d85..43b9c126 100644 --- a/Controller/TranslateController.php +++ b/Controller/TranslateController.php @@ -26,7 +26,9 @@ use JMS\TranslationBundle\Util\FileUtils; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Twig\Environment; /** * Translate Controller. @@ -45,15 +47,21 @@ class TranslateController */ private $loader; + /** + * @var Environment|null + */ + private $twig; + /** * @var string */ private $sourceLanguage; - public function __construct(ConfigFactory $configFactory, LoaderManager $loader) + public function __construct(ConfigFactory $configFactory, LoaderManager $loader, ?Environment $twig = null) { $this->configFactory = $configFactory; $this->loader = $loader; + $this->twig = $twig; } /** @@ -67,7 +75,7 @@ public function setSourceLanguage($lang) /** * @param Request $request * - * @return array + * @return Response|array * * @Route("/", name="jms_translation_index", options = {"i18n" = false}) * @Template("@JMSTranslation/Translate/index.html.twig") @@ -136,7 +144,7 @@ public function indexAction(Request $request) $existingMessages[$id] = $message; } - return [ + $variables = [ 'selectedConfig' => $config, 'configs' => $configs, 'selectedDomain' => $domain, @@ -151,5 +159,11 @@ public function indexAction(Request $request) 'file' => (string) $files[$domain][$locale][1], 'sourceLanguage' => $this->sourceLanguage, ]; + + if (null !== $this->twig) { + return new Response($this->twig->render('@JMSTranslation/Translate/index.html.twig', $variables)); + } + + return $variables; } } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index c7de8031..e57de45b 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -41,6 +41,7 @@ + %jms_translation.source_language%