Skip to content

Commit f1a337e

Browse files
authored
Merge pull request #85 from Crovitche-1623/patch-1
feat: Allow to use an existing translator
2 parents bd37bda + 7aec814 commit f1a337e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/TranslationDriver/SymfonyTranslationDriver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Symfony\Component\Translation\Loader\MoFileLoader;
88
use Symfony\Component\Translation\Translator;
9+
use Symfony\Contracts\Translation\TranslatorInterface;
910

1011
class SymfonyTranslationDriver implements TranslationDriverInterface
1112
{
@@ -19,9 +20,12 @@ class SymfonyTranslationDriver implements TranslationDriverInterface
1920
*/
2021
private $locale = 'en';
2122

22-
public function __construct(?string $cacheDirectory = null)
23+
/**
24+
* @param string|null $cacheDirectory useful only if the given $translator is null.
25+
*/
26+
public function __construct(?string $cacheDirectory = null, ?TranslatorInterface $translator = null)
2327
{
24-
$this->translator = new Translator($this->locale, null, $cacheDirectory);
28+
$this->translator = $translator ?: new Translator($this->locale, null, $cacheDirectory);
2529
$this->translator->addLoader('mo', new MoFileLoader());
2630
}
2731

0 commit comments

Comments
 (0)