Skip to content
Permalink
Browse files

extension improvments

  • Loading branch information
Aleš
Aleš committed Oct 1, 2019
1 parent 644dce6 commit 7bbdfbdcd4e4cab6bf51b94040492976b0b9c8c3
Showing with 7 additions and 10 deletions.
  1. +1 −0 composer.json
  2. +4 −2 src/DI/TranslationExtension.php
  3. +2 −8 tests/Tests/Translator.phpt
@@ -24,6 +24,7 @@
"symfony/config": "^4.2"
},
"require-dev": {
"nette/application": "^3.0",
"nette/bootstrap": "^3.0",
"nette/database": "^3.0",
"nette/robot-loader": " ^3.0",
@@ -168,12 +168,14 @@ public function beforeCompile(): void
$tracyPanel = $builder->getDefinition($this->prefix('tracyPanel'));
}
if ($builder->hasDefinition('latte.latteFactory')) {
$latteFactoryName = $builder->getByType(Nette\Bridges\ApplicationLatte\ILatteFactory::class);
if ($latteFactoryName !== null) {
$latteFilters = $builder->addDefinition($this->prefix('latte.filters'))
->setFactory(Contributte\Translation\Latte\Filters::class);
/** @var Nette\DI\Definitions\FactoryDefinition $latteFactory */
$latteFactory = $builder->getDefinition('latte.latteFactory');
$latteFactory = $builder->getDefinition($latteFactoryName);
$latteFactory->getResultDefinition()
->addSetup('?->onCompile[] = function (Latte\\Engine $engine): void { ?::install($engine->getCompiler()); }', ['@self', new Nette\PhpGenerator\PhpLiteral(Contributte\Translation\Latte\Macros::class)])
@@ -150,14 +150,8 @@ class Translator extends Tests\TestAbstract
{
$container = $this->createContainer();
/** @var Nette\Localization\ITranslator $translator */
$translator = $container->getByType(Nette\Localization\ITranslator::class);
$latte = (new Latte\Engine())
->addProvider('translator', $translator)
->addFilter('translate', [new Contributte\Translation\Latte\Filters($translator), 'translate']);
Contributte\Translation\Latte\Macros::install($latte->getCompiler());
/** @var Latte\Engine $latte */
$latte = $container->getByType(Nette\Bridges\ApplicationLatte\ILatteFactory::class)->create();
Tester\Assert::same('Hello', $latte->renderToString(Tester\FileMock::create('{_messages.hello}')));
Tester\Assert::same('Hello', $latte->renderToString(Tester\FileMock::create('{_}messages.hello{/_}')));

0 comments on commit 7bbdfbd

Please sign in to comment.
You can’t perform that action at this time.