Skip to content

Commit

Permalink
nette 3.1 compatibility (Kdyby#183)
Browse files Browse the repository at this point in the history
* 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]>

Co-authored-by: Jáchym Toušek <[email protected]>
  • Loading branch information
2 people authored and Jirka Hrazdil committed Apr 27, 2022
1 parent c009862 commit d0785b8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
10 changes: 6 additions & 4 deletions src/DI/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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) {
Expand Down
71 changes: 49 additions & 22 deletions tests/KdybyTests/Translation/LatteExtractorTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace KdybyTests\Translation;

use Kdyby\Translation\Extractors\LatteExtractor;
use Latte\Engine;
use Symfony\Component\Translation\MessageCatalogue;
use Tester\Assert;

Expand All @@ -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()
Expand All @@ -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());
}

}
Expand Down

0 comments on commit d0785b8

Please sign in to comment.