From d0785b8edc6ddfb11d6ada0d72be8c0074c8d922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Z=C3=A1ruba?= Date: Fri, 19 Feb 2021 07:26:12 +0100 Subject: [PATCH] nette 3.1 compatibility (#183) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Co-authored-by: Jáchym Toušek --- src/DI/TranslationExtension.php | 10 +-- .../Translation/LatteExtractorTest.phpt | 71 +++++++++++++------ 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/DI/TranslationExtension.php b/src/DI/TranslationExtension.php index ac256215..d1def1dd 100644 --- a/src/DI/TranslationExtension.php +++ b/src/DI/TranslationExtension.php @@ -10,6 +10,7 @@ namespace Kdyby\Translation\DI; +use Closure; use Kdyby\Console\DI\ConsoleExtension; use Kdyby\Monolog\Logger as KdybyLogger; use Kdyby\Translation\Caching\PhpFileStorage; @@ -30,6 +31,7 @@ use Latte\Engine as LatteEngine; use Nette\Application\Application; use Nette\Bridges\ApplicationLatte\ILatteFactory; +use Nette\Bridges\ApplicationLatte\LatteFactory; use Nette\Configurator; use Nette\DI\Compiler; use Nette\DI\Definitions\FactoryDefinition; @@ -39,7 +41,6 @@ use Nette\PhpGenerator\PhpLiteral; use Nette\Schema\Expect; use Nette\Schema\Schema; -use Nette\Utils\Callback; use Nette\Utils\Finder; use Nette\Utils\Validators; use Symfony\Component\Translation\Extractor\ChainExtractor; @@ -296,12 +297,12 @@ public function beforeCompile() ->addSetup('addFilter', ['translate', [$this->prefix('@helpers'), 'translateFilterAware']]); }; - $latteFactoryService = $builder->getByType(ILatteFactory::class); + $latteFactoryService = $builder->getByType(LatteFactory::class) ?: $builder->getByType(ILatteFactory::class); if (!$latteFactoryService || !self::isOfType($builder->getDefinition($latteFactoryService)->getClass(), LatteEngine::class)) { $latteFactoryService = 'nette.latteFactory'; } - if ($builder->hasDefinition($latteFactoryService) && self::isOfType($builder->getDefinition($latteFactoryService)->getClass(), ILatteFactory::class)) { + if ($builder->hasDefinition($latteFactoryService) && (self::isOfType($builder->getDefinition($latteFactoryService)->getClass(), LatteFactory::class) || self::isOfType($builder->getDefinition($latteFactoryService)->getClass(), ILatteFactory::class))) { $registerToLatte($builder->getDefinition($latteFactoryService)); } @@ -370,7 +371,8 @@ public function beforeCompile() $config['dirs'] = array_map(function ($dir) use ($builder) { return str_replace((DIRECTORY_SEPARATOR === '/') ? '\\' : '/', DIRECTORY_SEPARATOR, Helpers::expand($dir, $builder->parameters)); }, $config['dirs']); - $dirs = array_values(array_filter($config['dirs'], fn(string $dir) => \is_dir($dir))); + + $dirs = array_values(array_filter($config['dirs'], fn(string $dir) => \is_dir($dir))); if (count($dirs) > 0) { foreach ($dirs as $dir) { diff --git a/tests/KdybyTests/Translation/LatteExtractorTest.phpt b/tests/KdybyTests/Translation/LatteExtractorTest.phpt index db6bc178..2bd38db4 100644 --- a/tests/KdybyTests/Translation/LatteExtractorTest.phpt +++ b/tests/KdybyTests/Translation/LatteExtractorTest.phpt @@ -9,6 +9,7 @@ namespace KdybyTests\Translation; use Kdyby\Translation\Extractors\LatteExtractor; +use Latte\Engine; use Symfony\Component\Translation\MessageCatalogue; use Tester\Assert; @@ -23,17 +24,30 @@ class LatteExtractorTest extends \KdybyTests\Translation\TestCase $catalogue = new MessageCatalogue('cs_CZ'); $extractor->extract(__DIR__ . '/data/extractor-files', $catalogue); - - Assert::same([ - 'messages' => [ - 'Important title' => 'Important title', - 'Another important title' => 'Another important title', - "\nInteresting article about interesting topic\n" => "\nInteresting article about interesting topic\n", - 'Chapter 2' => 'Chapter 2', - 'none|one|many' => 'none|one|many', - 'sample.identificator' => 'sample.identificator', - ], - ], $catalogue->all()); + if (!defined(Engine::class . '::VERSION_ID') || Engine::VERSION_ID < 20900) { + $mess = [ + 'messages' => [ + 'Important title' => 'Important title', + 'Another important title' => 'Another important title', + "\nInteresting article about interesting topic\n" => "\nInteresting article about interesting topic\n", + 'Chapter 2' => 'Chapter 2', + 'none|one|many' => 'none|one|many', + 'sample.identificator' => 'sample.identificator', + ], + ]; + } else { + $mess = [ + 'messages' => [ + '("Important title")' => '("Important title")', + "('Another important title')" => "('Another important title')", + "\nInteresting article about interesting topic\n" => "\nInteresting article about interesting topic\n", + "('Chapter 2')" => "('Chapter 2')", + 'none|one|many' => 'none|one|many', + 'sample.identificator' => 'sample.identificator', + ], + ]; + } + Assert::same($mess, $catalogue->all()); } public function testExtractDirectoryWithPrefix() @@ -43,17 +57,30 @@ class LatteExtractorTest extends \KdybyTests\Translation\TestCase $catalogue = new MessageCatalogue('cs_CZ'); $extractor->extract(__DIR__ . '/data/extractor-files', $catalogue); - - Assert::same([ - 'messages' => [ - 'homepage.Important title' => 'Important title', - 'homepage.Another important title' => 'Another important title', - "homepage.\nInteresting article about interesting topic\n" => "\nInteresting article about interesting topic\n", - 'homepage.Chapter 2' => 'Chapter 2', - 'homepage.none|one|many' => 'none|one|many', - 'homepage.sample.identificator' => 'sample.identificator', - ], - ], $catalogue->all()); + if (!defined(Engine::class . '::VERSION_ID') || Engine::VERSION_ID < 20900) { + $mess = [ + 'messages' => [ + 'homepage.Important title' => 'Important title', + 'homepage.Another important title' => 'Another important title', + "homepage.\nInteresting article about interesting topic\n" => "\nInteresting article about interesting topic\n", + 'homepage.Chapter 2' => 'Chapter 2', + 'homepage.none|one|many' => 'none|one|many', + 'homepage.sample.identificator' => 'sample.identificator', + ], + ]; + } else { + $mess = [ + 'messages' => [ + 'homepage.("Important title")' => '("Important title")', + "homepage.('Another important title')" => "('Another important title')", + "homepage.\nInteresting article about interesting topic\n" => "\nInteresting article about interesting topic\n", + "homepage.('Chapter 2')" => "('Chapter 2')", + 'homepage.none|one|many' => 'none|one|many', + 'homepage.sample.identificator' => 'sample.identificator', + ], + ]; + } + Assert::same($mess, $catalogue->all()); } }