Skip to content

Commit

Permalink
Fix latte pair macros compatibility (#185)
Browse files Browse the repository at this point in the history
* Fix the latte/latte compatibility

* nette 3.1 compatibility

* latte fix max compatibility version

* fix cs

* Update .travis.yml

* latte/latte 2.10.1 compatibility

* fix if not exists latte engine constant

* clearing .travis.yml

* clearing .gitignore

* composer.json - original dependence latte/latte

* Update tests/KdybyTests/Translation/LatteExtractorTest.phpt

* useless variables in LatteExtractorTest.phpt

* CS Squiz.Strings.DoubleQuoteUsage.NotRequired was excluded from Extractor test

* Update LatteExtractorTest.phpt

* Update ruleset.xml

* Update src/DI/TranslationExtension.php

Co-authored-by: Jáchym Toušek <[email protected]>

* adding pair latte macro test

* adding pair latte macro test

Co-authored-by: Jaroslav Líbal <[email protected]>
Co-authored-by: Jáchym Toušek <[email protected]>
  • Loading branch information
3 people authored Apr 25, 2021
1 parent 57124c2 commit 4c4a02a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Latte/TranslateMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Kdyby\Translation\PrefixedTranslator;
use Latte\Compiler;
use Latte\Engine;
use Latte\MacroNode;
use Latte\PhpWriter;

Expand Down Expand Up @@ -48,7 +49,15 @@ public function macroTranslate(MacroNode $node, PhpWriter $writer)
$value = 'ob_get_clean()';
}

return $writer->write('$_fi = new LR\FilterInfo(%var); echo %modifyContent($this->filters->filterContent("translate", $_fi, %raw))', $node->context[0], $value);
if (!defined(Engine::class . '::VERSION_ID') || Engine::VERSION_ID < 20804) {
return $writer->write('$_fi = new LR\FilterInfo(%var); echo %modifyContent($this->filters->filterContent("translate", $_fi, %raw))', $node->context[0], $value);
}

if (Engine::VERSION_ID >= 20900 && Engine::VERSION_ID < 20902) {
return $writer->write('$__fi = new LR\FilterInfo(%var); echo %modifyContent($this->filters->filterContent("translate", $__fi, %raw))', $node->context[0], $value);
}

return $writer->write('$ʟ_fi = new LR\FilterInfo(%var); echo %modifyContent($this->filters->filterContent("translate", $ʟ_fi, %raw))', $node->context[0], $value);

} elseif ($node->args !== '') {
$node->empty = TRUE;
Expand Down
7 changes: 7 additions & 0 deletions tests/KdybyTests/Translation/TranslateMacrosTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ front.missingKey.namedHelloCounting' . "\n", $this->template->__toString());
Assert::same([], $handler->getRecords());
}

public function testPairMacro()
{
$this->template->setFile(__DIR__ . '/data/files/pairMacro.latte');
$expected = 'Hello';
Assert::match($expected, $this->template->__toString());
}

}

(new TranslateMacrosTest())->run();
1 change: 1 addition & 0 deletions tests/KdybyTests/Translation/data/files/pairMacro.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{_}Hello{/_}

0 comments on commit 4c4a02a

Please sign in to comment.