Browse Source

Port no-location option to 3.0

Port the no-location option added to the `i18n extract` task in #7005 to
3.0.
Mark Story 10 years ago
parent
commit
dbf2b42c6c
2 changed files with 35 additions and 1 deletions
  1. 8 1
      src/Shell/Task/ExtractTask.php
  2. 27 0
      tests/TestCase/Shell/Task/ExtractTaskTest.php

+ 8 - 1
src/Shell/Task/ExtractTask.php

@@ -337,6 +337,10 @@ class ExtractTask extends Shell
         ])->addOption('extract-core', [
             'help' => 'Extract messages from the CakePHP core libs.',
             'choices' => ['yes', 'no']
+        ])->addOption('no-location', [
+            'boolean' => true,
+            'default' => false,
+            'help' => 'Do not write file locations for each extracted message.',
         ]);
 
         return $parser;
@@ -454,7 +458,10 @@ class ExtractTask extends Shell
                         $occurrences[] = $file . ':' . implode(';', $lines);
                     }
                     $occurrences = implode("\n#: ", $occurrences);
-                    $header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
+                    $header = "\n";
+                    if (!$this->param('no-location')) {
+                        $header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
+                    }
 
                     $sentence = '';
                     if ($context !== "") {

+ 27 - 0
tests/TestCase/Shell/Task/ExtractTaskTest.php

@@ -159,6 +159,33 @@ class ExtractTaskTest extends TestCase
         $pattern = '/\#: .*default\.ctp:\d+\n/';
         $this->assertNotRegExp($pattern, $result);
     }
+    /**
+     * testExtractWithoutLocations method
+     *
+     * @return void
+     */
+    public function testExtractWithoutLocations()
+    {
+
+        $this->Task->params['paths'] = TEST_APP . 'TestApp/Template';
+        $this->Task->params['output'] = $this->path . DS;
+        $this->Task->params['exclude'] = 'Pages,Layout';
+        $this->Task->params['extract-core'] = 'no';
+        $this->Task->params['no-location'] = true;
+
+
+        $this->Task->expects($this->never())->method('err');
+        $this->Task->expects($this->any())->method('in')
+            ->will($this->returnValue('y'));
+
+        $this->Task->main();
+        $this->assertTrue(file_exists($this->path . DS . 'default.pot'));
+
+        $result = file_get_contents($this->path . DS . 'default.pot');
+
+        $pattern = '/\n\#: .*\n/';
+        $this->assertNotRegExp($pattern, $result);
+    }
 
     /**
      * test extract can read more than one path.