Skip to content

Commit 8cc895d

Browse files
committed
Template: filter translate is content-type aware
1 parent 9e7cd60 commit 8cc895d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Bridges/ApplicationLatte/Template.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public function registerHelperLoader($loader)
122122
*/
123123
public function setTranslator(Nette\Localization\ITranslator $translator = NULL)
124124
{
125-
$this->latte->addFilter('translate', $translator === NULL ? NULL : [$translator, 'translate']);
125+
$this->latte->addFilter('translate', $translator === NULL ? NULL : function (Latte\Runtime\FilterInfo $fi, ...$args) use ($translator) {
126+
return $translator->translate(...$args);
127+
});
126128
return $this;
127129
}
128130

src/Bridges/ApplicationLatte/TemplateFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Nette;
1111
use Nette\Application\UI;
12+
use Latte;
1213

1314

1415
/**
@@ -80,7 +81,7 @@ public function createTemplate(UI\Control $control = NULL)
8081
});
8182

8283
if (!isset($latte->getFilters()['translate'])) {
83-
$latte->addFilter('translate', function () {
84+
$latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi) {
8485
throw new Nette\InvalidStateException('Translator has not been set. Set translator using $template->setTranslator().');
8586
});
8687
}

0 commit comments

Comments
 (0)