- Fixed #ZETACOMP-2: comments should be supported in Extractor
(Thanks Maxime Thomas)
git-svn-id: https://svn.apache.org/repos/asf/incubator/zetacomponents/trunk@1153790 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/TemplateTranslationTiein/src/visitors/string_extracter.php b/TemplateTranslationTiein/src/visitors/string_extracter.php
index 8d83a41..e0d1731 100644
--- a/TemplateTranslationTiein/src/visitors/string_extracter.php
+++ b/TemplateTranslationTiein/src/visitors/string_extracter.php
@@ -117,7 +117,7 @@
public function visitTranslationTstNode( ezcTemplateTranslationTstNode $node )
{
$string = $node->string->accept( $this );
- $comment = $node->comment ? $node->comment->accept( $this )->value : null;
+ $comment = $node->comment ? $node->comment->value : null;
$file = realpath( $node->source->stream );
$line = $node->string->startCursor->line;
$column = $node->string->startCursor->column + 1;
diff --git a/TemplateTranslationTiein/tests/extracter.php b/TemplateTranslationTiein/tests/extracter.php
index ef61e0c..974a547 100644
--- a/TemplateTranslationTiein/tests/extracter.php
+++ b/TemplateTranslationTiein/tests/extracter.php
@@ -110,6 +110,29 @@
);
}
+ function testExtracterWithComments()
+ {
+ $file = dirname( __FILE__ ) . '/test_files/test_with_comments.ezt';
+ $source = new ezcTemplateSourceCode( $file, $file );
+ $source->load();
+
+ $parser = new ezcTemplateParser( $source, new ezcTemplate() );
+ $tst = $parser->parseIntoNodeTree();
+
+ $et = new ezcTemplateTranslationStringExtracter( $parser );
+ $eted = $tst->accept( $et );
+
+ $tr = $et->getTranslation();
+
+ self::assertEquals(
+ array( 'foo' ),
+ array_keys( $this->readAttribute( $tr['test'], 'translationMap' ) )
+ );
+
+ $translationMap = $this->readAttribute( $tr['test'], 'translationMap' );
+ self::assertEquals( "some comment", $translationMap['foo']->comment );
+ }
+
function testUnifyFileName()
{
ob_start();
diff --git a/TemplateTranslationTiein/tests/test_files/test_with_comments.ezt b/TemplateTranslationTiein/tests/test_files/test_with_comments.ezt
new file mode 100644
index 0000000..cde6fff
--- /dev/null
+++ b/TemplateTranslationTiein/tests/test_files/test_with_comments.ezt
@@ -0,0 +1,2 @@
+{tr_context "test"}
+{tr "foo" comment "some comment"}