Merge pull request #7005 from wnasich/pot-without-references

Generate .pot files without references
This commit is contained in:
Mark Story 2015-07-15 21:34:38 -04:00
commit 6fa3195de1
2 changed files with 42 additions and 7 deletions

View file

@ -316,6 +316,10 @@ class ExtractTask extends AppShell {
))->addOption('merge', array(
'help' => __d('cake_console', 'Merge all domain and category strings into the default.po file.'),
'choices' => array('yes', 'no')
))->addOption('no-location', array(
'boolean' => true,
'default' => false,
'help' => __d('cake_console', 'Do not write lines with locations'),
))->addOption('output', array(
'help' => __d('cake_console', 'Full path to output directory.')
))->addOption('files', array(
@ -572,14 +576,17 @@ class ExtractTask extends AppShell {
foreach ($translations as $msgid => $contexts) {
foreach ($contexts as $context => $details) {
$plural = $details['msgid_plural'];
$files = $details['references'];
$occurrences = array();
foreach ($files as $file => $lines) {
$lines = array_unique($lines);
$occurrences[] = $file . ':' . implode(';', $lines);
$header = '';
if (empty($this->params['no-location'])) {
$files = $details['references'];
$occurrences = array();
foreach ($files as $file => $lines) {
$lines = array_unique($lines);
$occurrences[] = $file . ':' . implode(';', $lines);
}
$occurrences = implode("\n#: ", $occurrences);
$header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
}
$occurrences = implode("\n#: ", $occurrences);
$header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
$sentence = '';
if ($context) {

View file

@ -221,6 +221,34 @@ class ExtractTaskTest extends CakeTestCase {
$this->assertNotRegExp($pattern, $result);
}
/**
* testExtractWithoutLocations method
*
* @return void
*/
public function testExtractWithoutLocations() {
$this->Task->interactive = false;
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages';
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'no';
$this->Task->params['merge'] = '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->expects($this->never())->method('_stop');
$this->Task->execute();
$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 exclusions
*