Skip to content

Commit

Permalink
Merge pull request #569 from deguif/get-rid-of-template-sensio-framew…
Browse files Browse the repository at this point in the history
…ork-extra-bundle

Allow to use translate controller without sensio/framework-extra-bundle
  • Loading branch information
goetas authored Dec 19, 2022
2 parents 153f4c9 + cc4301d commit bf2628f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Controller/TranslateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand All @@ -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")
Expand Down Expand Up @@ -136,7 +144,7 @@ public function indexAction(Request $request)
$existingMessages[$id] = $message;
}

return [
$variables = [
'selectedConfig' => $config,
'configs' => $configs,
'selectedDomain' => $domain,
Expand All @@ -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;
}
}
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<service id="jms_translation.controller.translate_controller" class="%jms_translation.controller.translate_controller.class%" public="true">
<argument type="service" id="jms_translation.config_factory"/>
<argument type="service" id="jms_translation.loader_manager"/>
<argument type="service" id="twig"/>
<call method="setSourceLanguage">
<argument>%jms_translation.source_language%</argument>
</call>
Expand Down

0 comments on commit bf2628f

Please sign in to comment.