Skip to content

Commit becff8a

Browse files
authored
Merge pull request #151 from tkleinhakisa/master
fixed error when using variable in transChoice
2 parents 598bbe7 + 086438f commit becff8a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Visitor/Php/Symfony/ContainerAwareTransChoice.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ public function enterNode(Node $node): ?Node
4242
}
4343
$name = (string) $node->name;
4444

45-
//If $this->get('translator')->trans('foobar')
45+
//If $this->get('translator')->transChoice('foobar')
4646
if ('transChoice' === $name) {
4747
$label = $this->getStringArgument($node, 0);
48+
if (null === $label) {
49+
return null;
50+
}
4851
$domain = $this->getStringArgument($node, 3);
4952

5053
$this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]);

tests/Resources/Php/Symfony/ContainerAwareTransChoice.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ public function newAction()
1313

1414
return array();
1515
}
16+
17+
public function transWithVariable()
18+
{
19+
$var = 'toto';
20+
$translated = $this->get('translator')->transChoice($var);
21+
}
1622
}

0 commit comments

Comments
 (0)