From dbf2b42c6c69bc9226d3cff6950f8e8c112433aa Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 15 Jul 2015 22:05:03 -0400 Subject: [PATCH] Port no-location option to 3.0 Port the no-location option added to the `i18n extract` task in #7005 to 3.0. --- src/Shell/Task/ExtractTask.php | 9 ++++++- tests/TestCase/Shell/Task/ExtractTaskTest.php | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Shell/Task/ExtractTask.php b/src/Shell/Task/ExtractTask.php index db171881394..d6980204996 100644 --- a/src/Shell/Task/ExtractTask.php +++ b/src/Shell/Task/ExtractTask.php @@ -337,6 +337,10 @@ public function getOptionParser() ])->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 @@ protected function _buildFiles() $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 !== "") { diff --git a/tests/TestCase/Shell/Task/ExtractTaskTest.php b/tests/TestCase/Shell/Task/ExtractTaskTest.php index ec6e43ab458..ffd51769fb9 100644 --- a/tests/TestCase/Shell/Task/ExtractTaskTest.php +++ b/tests/TestCase/Shell/Task/ExtractTaskTest.php @@ -159,6 +159,33 @@ public function testExtractWithExclude() $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.