Skip to content

Commit

Permalink
use translate macro in template
Browse files Browse the repository at this point in the history
  • Loading branch information
KuceraMartin committed Jul 4, 2017
1 parent d095c67 commit afe04d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Datagrid.blocks.latte
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
{/define}

{define row-actions-edit-link}
<a href="{link edit! $primary}" class="ajax" data-datagrid-edit>{$control->translate(nextras.datagrid.edit.label)}</a>
<a href="{link edit! $primary}" class="ajax" data-datagrid-edit>{_}nextras.datagrid.edit.label{/_}</a>
{/define}

{define row}
Expand Down Expand Up @@ -160,23 +160,23 @@
{define pagination}
<div class="grid-paginator">
{if $paginator->isFirst()}
<span{$control->translate(nextras.datagrid.pagination.first)}</span>
<span{$control->translate(nextras.datagrid.pagination.previous)}</span>
<span{_}nextras.datagrid.pagination.first{/_}</span>
<span{_}nextras.datagrid.pagination.previous{/_}</span>
{else}
<a href="{link paginate!, 'page' => 1}" class="ajax"{$control->translate(nextras.datagrid.pagination.first)}</a>
<a href="{link paginate!, 'page' => $paginator->page - 1}" class="ajax"{$control->translate(nextras.datagrid.pagination.previous)}</a>
<a href="{link paginate!, 'page' => 1}" class="ajax"{_}nextras.datagrid.pagination.first{/_}</a>
<a href="{link paginate!, 'page' => $paginator->page - 1}" class="ajax"{_}nextras.datagrid.pagination.previous{/_}</a>
{/if}

<span>
<span>{$paginator->page}</span> / <span>{$paginator->pageCount}</span>
</span>

{if $paginator->isLast()}
<span>{$control->translate(nextras.datagrid.pagination.next)} »</span>
<span>{$control->translate(nextras.datagrid.pagination.last)} »</span>
<span>{_}nextras.datagrid.pagination.next{/_} »</span>
<span>{_}nextras.datagrid.pagination.last{/_} »</span>
{else}
<a href="{link paginate!, 'page' => $paginator->page + 1}" class="ajax">{$control->translate(nextras.datagrid.pagination.next)} »</a>
<a href="{link paginate!, 'page' => $paginator->pageCount}" class="ajax">{$control->translate(nextras.datagrid.pagination.last)} »</a>
<a href="{link paginate!, 'page' => $paginator->page + 1}" class="ajax">{_}nextras.datagrid.pagination.next{/_} »</a>
<a href="{link paginate!, 'page' => $paginator->pageCount}" class="ajax">{_}nextras.datagrid.pagination.last{/_} »</a>
{/if}
</div>
{/define}
6 changes: 6 additions & 0 deletions src/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ public function translate($s, $count = null)

public function render()
{
if (!$this->template instanceof Template) {
throw new LogicException('Template must be instance of ' . Template::class);
}

if ($this->filterFormFactory) {
$this['form']['filter']->setDefaults($this->filter);
}
Expand All @@ -288,6 +292,8 @@ public function render()
$this->template->showFilterCancel = $this->filterDataSource != $this->filterDefaults; // @ intentionaly
$this->template->setFile(__DIR__ . '/Datagrid.latte');

$this->template->setTranslator($this->translator);

$this->onRender($this);
$this->template->render();
}
Expand Down
5 changes: 5 additions & 0 deletions src/exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
class InvalidArgumentException extends \InvalidArgumentException
{
}


class LogicException extends \LogicException
{
}

0 comments on commit afe04d3

Please sign in to comment.