diff --git a/src/TranslationDriver/SymfonyTranslationDriver.php b/src/TranslationDriver/SymfonyTranslationDriver.php index 6ff144aa..32770434 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(?string $cacheDirectory = null, ?TranslatorInterface $translator = null) { - $this->translator = new Translator($this->locale, null, $cacheDirectory); + $this->translator = $translator ?: new Translator($this->locale, null, $cacheDirectory); $this->translator->addLoader('mo', new MoFileLoader()); }