Skip to content

Commit 3393fb2

Browse files
authored
Twig 1 bugfixes (#38)
* Twig 1 bugfixes * Bugfixes
1 parent 0fdb965 commit 3393fb2

File tree

7 files changed

+23
-3
lines changed

7 files changed

+23
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ matrix:
2626
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci"
2727

2828
install:
29-
- travis_retry composer update --prefer-dist --no-interaction
29+
- travis_retry composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
3030

3131
script:
3232
- $TEST_COMMAND

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
44

55
## UNRELEASED
66

7+
## 1.1.1
8+
9+
### Fixed
10+
11+
- Make sure we test with the lowest version on Travis
12+
- Fixed minor bugs for Twig 1.x.
13+
714
## 1.1.0
815

916
### Added

src/FileExtractor/TwigFileExtractor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ public function getNodeVisitors()
7676
{
7777
return $this->visitors;
7878
}
79+
80+
public function getName()
81+
{
82+
return 'php.translation';
83+
}
7984
}

src/Visitor/Twig/TranslationBlock.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Translation\Extractor\Visitor\Twig;
1313

14+
use Symfony\Bridge\Twig\Node\TransNode;
15+
use Translation\Extractor\Model\SourceLocation;
1416
use Translation\Extractor\Visitor\BaseVisitor;
1517
use Twig_Environment;
1618
use Twig_NodeInterface;

src/Visitor/Twig/TranslationFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Extractor\Visitor\Twig;
1313

14+
use Translation\Extractor\Model\SourceLocation;
1415
use Translation\Extractor\Visitor\BaseVisitor;
1516
use Twig_Environment;
1617
use Twig_NodeInterface;

src/Visitor/Twig/TwigVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(Worker $worker = null)
4242
*/
4343
public static function create()
4444
{
45-
if (\Twig_Environment::MAJOR_VERSION === 1) {
45+
if (-1 === version_compare(\Twig_Environment::VERSION, '2.0')) {
4646
return new Twig1Visitor();
4747
}
4848

src/Visitor/Twig/Worker.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ public function work($node, SourceCollection $collection, callable $getAbsoluteF
6060
));
6161
} elseif ($node instanceof TransNode) {
6262
// extract trans nodes
63+
$domain = self::UNDEFINED_DOMAIN;
64+
if ($node->hasNode('domain') && null !== $node->getNode('domain')) {
65+
$domain = $this->getReadDomainFromNode($node->getNode('domain'));
66+
}
67+
6368
$collection->addLocation(new SourceLocation(
6469
$node->getNode('body')->getAttribute('data'),
6570
$getAbsoluteFilePath(),
6671
$node->getTemplateLine(),
67-
['domain' => $node->hasNode('domain') ? $this->getReadDomainFromNode($node->getNode('domain')) : self::UNDEFINED_DOMAIN]
72+
['domain' => $domain]
6873
));
6974
}
7075

0 commit comments

Comments
 (0)