Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Added support for Translator [Kurtas]
Browse files Browse the repository at this point in the history
  • Loading branch information
holubj committed Oct 13, 2012
1 parent b86dabf commit 8060385
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Grid.php
Expand Up @@ -81,6 +81,9 @@ class Grid extends \Nette\Application\UI\Control
/** @var string */
public $messageNoRecords = 'Žádné záznamy';

/** @var \Nette\Localization\ITranslator */
protected $translator;

/**
* @param \Nette\Application\UI\Presenter $presenter
*/
Expand Down Expand Up @@ -755,6 +758,8 @@ protected function createComponentGridForm()
->getControlPrototype()
->addClass("grid-perpagesubmit");

$form->setTranslator($this->getTranslator());

$form->onSuccess[] = callback($this, "processGridForm");

return $form;
Expand Down Expand Up @@ -937,7 +942,34 @@ public function render()
$this->template->viewedTo = ($this->getPaginator()->getLength()+(($this->getPaginator()->getPage()-1)*$this->perPage));
}
$templatePath = !empty($this->templatePath) ? $this->templatePath : __DIR__."/templates/grid.latte";

if ($this->getTranslator() instanceof \Nette\Localization\ITranslator) {
$this->template->setTranslator($this->getTranslator());
}

$this->template->setFile($templatePath);
$this->template->render();
}

/**
* @param \Nette\Localization\ITranslator $translator
* @return Grid
*/
public function setTranslator(\Nette\Localization\ITranslator $translator)
{
$this->translator = $translator;

return $this;
}

/**
* @return \Nette\Localization\ITranslator|null
*/
public function getTranslator()
{
if($this->translator instanceof \Nette\Localization\ITranslator)
return $this->translator;

return null;
}
}

0 comments on commit 8060385

Please sign in to comment.