From 4c18139498ad8b72e56b7884b983c7ea0e933947 Mon Sep 17 00:00:00 2001 From: "Thibault G." Date: Mon, 8 Sep 2025 17:09:56 +0200 Subject: [PATCH 1/2] feat: Allow to use an existing translator --- src/TranslationDriver/SymfonyTranslationDriver.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/TranslationDriver/SymfonyTranslationDriver.php b/src/TranslationDriver/SymfonyTranslationDriver.php index 6ff144aa..bc228450 100644 --- a/src/TranslationDriver/SymfonyTranslationDriver.php +++ b/src/TranslationDriver/SymfonyTranslationDriver.php @@ -6,6 +6,7 @@ use Symfony\Component\Translation\Loader\MoFileLoader; use Symfony\Component\Translation\Translator; +use Symfony\Contracts\Translation\TranslatorInterface; class SymfonyTranslationDriver implements TranslationDriverInterface { @@ -19,9 +20,12 @@ class SymfonyTranslationDriver implements TranslationDriverInterface */ private $locale = 'en'; - public function __construct(?string $cacheDirectory = null) + /** + * @param string|null $cacheDirectory useful only if the given $translator is null. + */ + public function __construct(?TranslatorInterface $translator = null, ?string $cacheDirectory = null) { - $this->translator = new Translator($this->locale, null, $cacheDirectory); + $this->translator = $translator ?: new Translator($this->locale, null, $cacheDirectory); $this->translator->addLoader('mo', new MoFileLoader()); } From 7aec8147a2dee0aa7540fc4df1c9c2523d51d323 Mon Sep 17 00:00:00 2001 From: "Thibault G." Date: Mon, 8 Sep 2025 18:47:59 +0200 Subject: [PATCH 2/2] refactor: respect parameters order to preserve BC --- src/TranslationDriver/SymfonyTranslationDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TranslationDriver/SymfonyTranslationDriver.php b/src/TranslationDriver/SymfonyTranslationDriver.php index bc228450..32770434 100644 --- a/src/TranslationDriver/SymfonyTranslationDriver.php +++ b/src/TranslationDriver/SymfonyTranslationDriver.php @@ -23,7 +23,7 @@ class SymfonyTranslationDriver implements TranslationDriverInterface /** * @param string|null $cacheDirectory useful only if the given $translator is null. */ - public function __construct(?TranslatorInterface $translator = null, ?string $cacheDirectory = null) + public function __construct(?string $cacheDirectory = null, ?TranslatorInterface $translator = null) { $this->translator = $translator ?: new Translator($this->locale, null, $cacheDirectory); $this->translator->addLoader('mo', new MoFileLoader());