Skip to content

Commit 29a701d

Browse files
committed
Merge branch '3.4' into 4.3
* 3.4: Fix the translation commands when a template contains a syntax error [Validator] Update Slovenian translations
2 parents 3608566 + 49b824d commit 29a701d

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

Tests/Translation/TwigExtractorTest.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Translation\MessageCatalogue;
1818
use Symfony\Contracts\Translation\TranslatorInterface;
1919
use Twig\Environment;
20-
use Twig\Error\Error;
2120
use Twig\Loader\ArrayLoader;
2221

2322
class TwigExtractorTest extends TestCase
@@ -101,23 +100,15 @@ public function getLegacyExtractData()
101100
/**
102101
* @dataProvider resourcesWithSyntaxErrorsProvider
103102
*/
104-
public function testExtractSyntaxError($resources)
103+
public function testExtractSyntaxError($resources, array $messages)
105104
{
106-
$this->expectException('Twig\Error\Error');
107105
$twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
108106
$twig->addExtension(new TranslationExtension($this->getMockBuilder(TranslatorInterface::class)->getMock()));
109107

110108
$extractor = new TwigExtractor($twig);
111-
112-
try {
113-
$extractor->extract($resources, new MessageCatalogue('en'));
114-
} catch (Error $e) {
115-
$this->assertSame(\dirname(__DIR__).strtr('/Fixtures/extractor/syntax_error.twig', '/', \DIRECTORY_SEPARATOR), $e->getFile());
116-
$this->assertSame(1, $e->getLine());
117-
$this->assertSame('Unclosed "block".', $e->getMessage());
118-
119-
throw $e;
120-
}
109+
$catalogue = new MessageCatalogue('en');
110+
$extractor->extract($resources, $catalogue);
111+
$this->assertSame($messages, $catalogue->all());
121112
}
122113

123114
/**
@@ -126,9 +117,9 @@ public function testExtractSyntaxError($resources)
126117
public function resourcesWithSyntaxErrorsProvider()
127118
{
128119
return [
129-
[__DIR__.'/../Fixtures'],
130-
[__DIR__.'/../Fixtures/extractor/syntax_error.twig'],
131-
[new \SplFileInfo(__DIR__.'/../Fixtures/extractor/syntax_error.twig')],
120+
[__DIR__.'/../Fixtures', ['messages' => ['Hi!' => 'Hi!']]],
121+
[__DIR__.'/../Fixtures/extractor/syntax_error.twig', []],
122+
[new \SplFileInfo(__DIR__.'/../Fixtures/extractor/syntax_error.twig'), []],
132123
];
133124
}
134125

Translation/TwigExtractor.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bridge\Twig\Translation;
1313

1414
use Symfony\Component\Finder\Finder;
15-
use Symfony\Component\Finder\SplFileInfo;
1615
use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
1716
use Symfony\Component\Translation\Extractor\ExtractorInterface;
1817
use Symfony\Component\Translation\MessageCatalogue;
@@ -58,13 +57,7 @@ public function extract($resource, MessageCatalogue $catalogue)
5857
try {
5958
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
6059
} catch (Error $e) {
61-
if ($file instanceof \SplFileInfo) {
62-
$path = $file->getRealPath() ?: $file->getPathname();
63-
$name = $file instanceof SplFileInfo ? $file->getRelativePathname() : $path;
64-
$e->setSourceContext(new Source('', $name, $path));
65-
}
66-
67-
throw $e;
60+
// ignore errors, these should be fixed by using the linter
6861
}
6962
}
7063
}

0 commit comments

Comments
 (0)