Skip to content

Commit

Permalink
[TwigBridge] added missing transchoice filters whe extracting transla…
Browse files Browse the repository at this point in the history
…tions from templates
  • Loading branch information
fabpot committed Jan 2, 2012
1 parent 789d5ad commit c73e034
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Bridge/Twig/NodeVisitor/TranslationNodeVisitor.php
Expand Up @@ -59,6 +59,16 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
$node->getNode('node')->getAttribute('value'),
$node->getNode('arguments')->hasNode(1) ? $node->getNode('arguments')->getNode(1)->getAttribute('value') : null,
);
} elseif (
$node instanceof \Twig_Node_Expression_Filter &&
'transchoice' === $node->getNode('filter')->getAttribute('value') &&
$node->getNode('node') instanceof \Twig_Node_Expression_Constant
) {
// extract constant nodes with a trans filter
$this->messages[] = array(
$node->getNode('node')->getAttribute('value'),
$node->getNode('arguments')->hasNode(2) ? $node->getNode('arguments')->getNode(2)->getAttribute('value') : null,
);
} elseif ($node instanceof TransNode) {
// extract trans nodes
$this->messages[] = array(
Expand Down
Expand Up @@ -52,6 +52,9 @@ public function getExtractData()
array('{{ "new key" | trans() }}', array('new key' => 'messages')),
array('{{ "new key" | trans() | upper }}', array('new key' => 'messages')),
array('{{ "new key" | trans({}, "domain") }}', array('new key' => 'domain')),
array('{{ "new key" | transchoice(1) }}', array('new key' => 'messages')),
array('{{ "new key" | transchoice(1) | upper }}', array('new key' => 'messages')),
array('{{ "new key" | transchoice(1, {}, "domain") }}', array('new key' => 'domain')),
array('{% trans %}new key{% endtrans %}', array('new key' => 'messages')),
array('{% trans from "domain" %}new key{% endtrans %}', array('new key' => 'domain')),
array('{% set foo = "new key" | trans %}', array('new key' => 'messages')),
Expand Down

0 comments on commit c73e034

Please sign in to comment.