Permalink
Browse files

Fixes issue #7

  • Loading branch information...
1 parent c6e8ba8 commit 6b0cc16934b6e62ef07c8d2e59f9f13ff3193d3d @alecsammon alecsammon committed with fabpot Jan 25, 2011
Showing with 16 additions and 10 deletions.
  1. +16 −10 lib/Twig/Extensions/Node/Trans.php
@@ -104,19 +104,25 @@ protected function compileString(Twig_NodeInterface $body)
return array($body, array());
}
- $msg = '';
$vars = array();
- foreach ($body as $node) {
- if ($node instanceof Twig_Node_Print) {
- $n = $node->getNode('expr');
- while ($n instanceof Twig_Node_Expression_Filter) {
- $n = $n->getNode('node');
+
+ if (count($body)) {
+ $msg = '';
+
+ foreach ($body as $node) {
+ if ($node instanceof Twig_Node_Print) {
+ $n = $node->getNode('expr');
+ while ($n instanceof Twig_Node_Expression_Filter) {
+ $n = $n->getNode('node');
+ }
+ $msg .= sprintf('%%%s%%', $n->getAttribute('name'));
+ $vars[] = new Twig_Node_Expression_Name($n->getAttribute('name'), $n->getLine());
+ } else {
+ $msg .= $node->getAttribute('data');
}
- $msg .= sprintf('%%%s%%', $n->getAttribute('name'));
- $vars[] = new Twig_Node_Expression_Name($n->getAttribute('name'), $n->getLine());
- } else {
- $msg .= $node->getAttribute('data');
}
+ } else {
+ $msg = $body->getAttribute('data');
}
return array(new Twig_Node(array(new Twig_Node_Expression_Constant(trim($msg), $body->getLine()))), $vars);

0 comments on commit 6b0cc16

Please sign in to comment.