Skip to content

Commit

Permalink
Port no-location option to 3.0
Browse files Browse the repository at this point in the history
Port the no-location option added to the `i18n extract` task in #7005 to
3.0.
  • Loading branch information
markstory committed Jul 16, 2015
1 parent afa89ea commit dbf2b42
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Shell/Task/ExtractTask.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

This comment has been minimized.

Copy link
@wnasich

wnasich Jul 16, 2015

Contributor

@markstory I'm glad to see it ported to 3.0 and merged into 2.8! thanks. A little comment, if I'm not wrong, adding this line feed char here will result in 2 empty line in .pot file among sentences.

This comment has been minimized.

Copy link
@markstory

markstory Jul 16, 2015

Author Member

It might, I'll take a look.

if (!$this->param('no-location')) {
$header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
}

$sentence = '';
if ($context !== "") {
Expand Down
27 changes: 27 additions & 0 deletions tests/TestCase/Shell/Task/ExtractTaskTest.php
Expand Up @@ -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.
Expand Down

0 comments on commit dbf2b42

Please sign in to comment.