- Fixed #ZETACOMP-1: Template file extension is no longer hard coded
# there is a new "-e" argument in runextractor.php
# run runextractor.php --help for more informations


git-svn-id: https://svn.apache.org/repos/asf/incubator/zetacomponents/trunk@1087963 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/TemplateTranslationTiein/src/extractor.php b/TemplateTranslationTiein/src/extractor.php
index 996610b..4acdcd3 100644
--- a/TemplateTranslationTiein/src/extractor.php
+++ b/TemplateTranslationTiein/src/extractor.php
@@ -189,6 +189,22 @@
             )
         );
 
+        $this->input->registerOption(
+            new ezcConsoleOption(
+                "e",         // short
+                "extension", // long
+                ezcConsoleInput::TYPE_STRING,
+                'ezt',       // default
+                false,       // multiple
+                'Specifies the file extension for templates',
+                'Specifies the file extension to be used when searching for templates, default (ezt)',
+                array(),     // dependencies
+                array(),     // exclusions
+                true,        // arguments
+                false        // mandatory
+            )
+        );
+
         $this->input->argumentDefinition = new ezcConsoleArguments();
 
         $this->input->argumentDefinition[0] = new ezcConsoleArgument( "translation dir" );
@@ -254,7 +270,8 @@
         $usedContexts = array();
 
         // find the .ezt files and loop over them.
-        $it = ezcBaseFile::findRecursive( $templatePath, array( '@\.ezt$@' ) );
+        $fileExtension = $this->input->getOption( "extension" )->value;
+        $it = ezcBaseFile::findRecursive( $templatePath, array( "@\.${fileExtension}$@" ) );
         foreach ( $it as $item )
         {
             $pathname = $this->unifyFilepath( realpath( $item ), $templatePath );
@@ -450,4 +467,4 @@
         exit( -1 );
     }
 }
-?>
+?>
\ No newline at end of file
diff --git a/TemplateTranslationTiein/tests/extracter.php b/TemplateTranslationTiein/tests/extracter.php
index bffa28a..8a3fe4f 100644
--- a/TemplateTranslationTiein/tests/extracter.php
+++ b/TemplateTranslationTiein/tests/extracter.php
@@ -154,10 +154,42 @@
         );
     }
 
+    public function testRunNonEztTemplateExtension()
+    {
+        $origArgv = $_SERVER['argv'];
+        $tmpDir = sys_get_temp_dir();
+        $testFileDir = "TemplateTranslationTiein/tests/test_files/extractor/templates/customtplextension";
+        $tmpFile = "${tmpDir}/en.xml";
+
+        ob_start();
+        $extractor = new ezcTemplateTranslationExtractor();
+
+        $_SERVER['argv'] = array (
+            0 => 'TemplateTranslationTiein/src/runextractor.php',
+            1 => '-t',
+            2 => $testFileDir,
+            3 => '-e',
+            4 => 'tpl',
+            5 => $tmpDir,
+        );
+
+        $extractor->run();
+        ob_end_clean();
+
+        $_SERVER['argv'] = $origArgv;
+
+        $this->assertEquals(
+            file_get_contents( "${testFileDir}/output.xml" ),
+            file_get_contents( $tmpFile )
+        );
+
+        unlink( $tmpFile );
+    }
+
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( 'ezcTemplateTranslationExtracterTest' );
     }
 }
 
-?>
+?>
\ No newline at end of file
diff --git a/TemplateTranslationTiein/tests/test_files/extractor/templates/customtplextension/output.xml b/TemplateTranslationTiein/tests/test_files/extractor/templates/customtplextension/output.xml
new file mode 100644
index 0000000..dac8ed1
--- /dev/null
+++ b/TemplateTranslationTiein/tests/test_files/extractor/templates/customtplextension/output.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TS>
+  <context>
+    <name>admin/forget_password</name>
+    <message>
+      <source>String to translate</source>
+      <translation type="unfinished">String to translate</translation>
+      <location filename="test.tpl" line="2"/>
+    </message>
+  </context>
+</TS>
diff --git a/TemplateTranslationTiein/tests/test_files/extractor/templates/customtplextension/test.tpl b/TemplateTranslationTiein/tests/test_files/extractor/templates/customtplextension/test.tpl
new file mode 100644
index 0000000..5bc1a16
--- /dev/null
+++ b/TemplateTranslationTiein/tests/test_files/extractor/templates/customtplextension/test.tpl
@@ -0,0 +1,2 @@
+{tr_context "admin/forget_password"}
+{tr "String to translate"}
\ No newline at end of file