diff --git a/src/Kollarovic/Admin/AdminControl.php b/src/Kollarovic/Admin/AdminControl.php index d55fd2e..103730f 100644 --- a/src/Kollarovic/Admin/AdminControl.php +++ b/src/Kollarovic/Admin/AdminControl.php @@ -6,6 +6,7 @@ use Kollarovic\Navigation\NavigationControl; use Nette\Application\UI\Control; use Nette\Application\UI\Form; +use Nette\Localization\ITranslator; use Nette\Security\User; @@ -24,6 +25,9 @@ class AdminControl extends Control /** @var ILoaderFactory */ private $loaderFactory; + /** @var ITranslator */ + private $translator; + /** @var User */ private $user; @@ -70,11 +74,12 @@ class AdminControl extends Control private $ajaxRequest = FALSE; - function __construct(ItemsFactory $itemsFactory, ILoaderFactory $loaderFactory, User $user) + function __construct(ItemsFactory $itemsFactory, ILoaderFactory $loaderFactory, User $user, ITranslator $translator = null) { $this->itemsFactory = $itemsFactory; $this->loaderFactory = $loaderFactory; $this->user = $user; + $this->translator = $translator; $this->templateFile = __DIR__ . '/templates/AdminControl.latte'; } @@ -300,7 +305,9 @@ public function handleSignOut() protected function createTemplate($class = NULL) { $template = parent::createTemplate($class); - if (!array_key_exists('translate', $template->getLatte()->getFilters())) { + if ($this->translator) { + $template->addFilter('translate', [$this->translator, 'translate']); + } else { $template->addFilter('translate', function($str){return $str;}); } return $template; @@ -332,7 +339,7 @@ protected function createComponentJs() protected function createComponentNavigation() { - return new NavigationControl($this->getRootItem()); + return new NavigationControl($this->getRootItem(), $this->translator); } diff --git a/src/Kollarovic/Admin/LoginControl.php b/src/Kollarovic/Admin/LoginControl.php index a8f723c..05ddb00 100644 --- a/src/Kollarovic/Admin/LoginControl.php +++ b/src/Kollarovic/Admin/LoginControl.php @@ -3,6 +3,7 @@ namespace Kollarovic\Admin; use Nette\Application\UI\Control; +use Nette\Localization\ITranslator; class LoginControl extends Control @@ -20,6 +21,9 @@ class LoginControl extends Control /** @var ILoaderFactory */ private $loaderFactory; + /** @var ITranslator */ + private $translator; + /** @var string */ private $pageTitle; @@ -36,10 +40,11 @@ class LoginControl extends Control private $passwordIcon; - function __construct(ILoginFormFactory $loginFormFactory, ILoaderFactory $loaderFactory) + function __construct(ILoginFormFactory $loginFormFactory, ILoaderFactory $loaderFactory, ITranslator $translator = null) { $this->loginFormFactory = $loginFormFactory; $this->loaderFactory = $loaderFactory; + $this->translator = $translator; $this->templateFile = __DIR__ . '/templates/LoginControl.latte'; } @@ -140,7 +145,9 @@ public function render(array $options = []) protected function createTemplate($class = NULL) { $template = parent::createTemplate($class); - if (!array_key_exists('translate', $template->getLatte()->getFilters())) { + if ($this->translator) { + $template->addFilter('translate', [$this->translator, 'translate']); + } else { $template->addFilter('translate', function($str){return $str;}); } return $template; diff --git a/tests/Admin/MockTranslator.php b/tests/Admin/MockTranslator.php deleted file mode 100644 index 4113a64..0000000 --- a/tests/Admin/MockTranslator.php +++ /dev/null @@ -1,16 +0,0 @@ -