Skip to content

Commit

Permalink
vlastny translator
Browse files Browse the repository at this point in the history
  • Loading branch information
Kollarovic committed Jun 4, 2019
1 parent 98458a0 commit c210003
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
13 changes: 10 additions & 3 deletions src/Kollarovic/Admin/AdminControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -24,6 +25,9 @@ class AdminControl extends Control
/** @var ILoaderFactory */
private $loaderFactory;

/** @var ITranslator */
private $translator;

/** @var User */
private $user;

Expand Down Expand Up @@ -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';
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -332,7 +339,7 @@ protected function createComponentJs()

protected function createComponentNavigation()
{
return new NavigationControl($this->getRootItem());
return new NavigationControl($this->getRootItem(), $this->translator);
}


Expand Down
11 changes: 9 additions & 2 deletions src/Kollarovic/Admin/LoginControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kollarovic\Admin;

use Nette\Application\UI\Control;
use Nette\Localization\ITranslator;


class LoginControl extends Control
Expand All @@ -20,6 +21,9 @@ class LoginControl extends Control
/** @var ILoaderFactory */
private $loaderFactory;

/** @var ITranslator */
private $translator;

/** @var string */
private $pageTitle;

Expand All @@ -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';
}

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 0 additions & 16 deletions tests/Admin/MockTranslator.php

This file was deleted.

6 changes: 0 additions & 6 deletions tests/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ navigation:
mail:
label: Mail
link: Setting:mail

services:
translator: Kollarovic\Admin\Test\MockTranslator
nette.latteFactory:
setup:
- addFilter('translate', [@translator, 'translate'])

0 comments on commit c210003

Please sign in to comment.