Skip to content

Commit

Permalink
Merge branch 'master' into fix-message-with-dot-at-the-end
Browse files Browse the repository at this point in the history
  • Loading branch information
lulco committed Feb 19, 2021
2 parents 022fb2a + 3adb0d8 commit c879918
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/DI/TranslationExtension.php
Expand Up @@ -31,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 Down Expand Up @@ -297,12 +298,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
71 changes: 49 additions & 22 deletions tests/KdybyTests/Translation/LatteExtractorTest.phpt
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 c879918

Please sign in to comment.