mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Using patch from 'wals' to add generic exclude option to the ExtractTask. Allows you to exclude path segments from the generated PO files.
Fixes #1138
This commit is contained in:
parent
efac10d3de
commit
fff8279c2b
2 changed files with 65 additions and 18 deletions
|
@ -90,6 +90,13 @@ class ExtractTask extends Shell {
|
||||||
*/
|
*/
|
||||||
private $__output = null;
|
private $__output = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of directories to exclude.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_exclude = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execution method always used for tasks
|
* Execution method always used for tasks
|
||||||
*
|
*
|
||||||
|
@ -97,6 +104,9 @@ class ExtractTask extends Shell {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function execute() {
|
function execute() {
|
||||||
|
if (!empty($this->params['exclude'])) {
|
||||||
|
$this->_exclude = explode(',', $this->params['exclude']);
|
||||||
|
}
|
||||||
if (isset($this->params['files']) && !is_array($this->params['files'])) {
|
if (isset($this->params['files']) && !is_array($this->params['files'])) {
|
||||||
$this->__files = explode(',', $this->params['files']);
|
$this->__files = explode(',', $this->params['files']);
|
||||||
}
|
}
|
||||||
|
@ -190,14 +200,17 @@ class ExtractTask extends Shell {
|
||||||
public function getOptionParser() {
|
public function getOptionParser() {
|
||||||
$parser = parent::getOptionParser();
|
$parser = parent::getOptionParser();
|
||||||
return $parser->description(__('CakePHP Language String Extraction:'))
|
return $parser->description(__('CakePHP Language String Extraction:'))
|
||||||
->addOption('app', array('help' => __('directory where your application is located.')))
|
->addOption('app', array('help' => __('Directory where your application is located.')))
|
||||||
->addOption('paths', array('help' => __('comma separted list of paths, full paths are needed.')))
|
->addOption('paths', array('help' => __('Comma separted list of paths, full paths are needed.')))
|
||||||
->addOption('merge', array(
|
->addOption('merge', array(
|
||||||
'help' => __('[yes|no] Merge all domain strings into the default.po file.'),
|
'help' => __('Merge all domain strings into the default.po file.'),
|
||||||
'choices' => array('yes', 'no')
|
'choices' => array('yes', 'no')
|
||||||
))
|
))
|
||||||
->addOption('output', array('help' => __('Full path to output directory.')))
|
->addOption('output', array('help' => __('Full path to output directory.')))
|
||||||
->addOption('files', array('help' => __('comma separated list of files, full paths are needed.')));
|
->addOption('files', array('help' => __('Comma separated list of files, full paths are needed.')))
|
||||||
|
->addOption('exclude', array(
|
||||||
|
'help' => __('Comma separated list of directories to exclude. Any path containing a path segment with the provided values will be skipped. E.g. test,vendors')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -502,9 +515,21 @@ class ExtractTask extends Shell {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __searchFiles() {
|
function __searchFiles() {
|
||||||
|
$pattern = false;
|
||||||
|
if (!empty($this->_exclude)) {
|
||||||
|
$pattern = '/[\/\\\\]' . implode('|', $this->_exclude) . '[\/\\\\]/';
|
||||||
|
}
|
||||||
foreach ($this->__paths as $path) {
|
foreach ($this->__paths as $path) {
|
||||||
$Folder = new Folder($path);
|
$Folder = new Folder($path);
|
||||||
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
|
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
|
||||||
|
if (!empty($pattern)) {
|
||||||
|
foreach ($files as $i => $file) {
|
||||||
|
if (preg_match($pattern, $file)) {
|
||||||
|
unset($files[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$files = array_values($files);
|
||||||
|
}
|
||||||
$this->__files = array_merge($this->__files, $files);
|
$this->__files = array_merge($this->__files, $files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
array('in', 'out', 'err', '_stop'),
|
array('in', 'out', 'err', '_stop'),
|
||||||
array($out, $out, $in)
|
array($out, $out, $in)
|
||||||
);
|
);
|
||||||
|
$this->path = TMP . 'tests' . DS . 'extract_task_test';
|
||||||
|
$Folder = new Folder($this->path . DS . 'locale', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,6 +59,9 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
unset($this->Task);
|
unset($this->Task);
|
||||||
|
|
||||||
|
$Folder = new Folder($this->path);
|
||||||
|
$Folder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,21 +70,18 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecute() {
|
public function testExecute() {
|
||||||
$path = TMP . 'tests' . DS . 'extract_task_test';
|
|
||||||
new Folder($path . DS . 'locale', true);
|
|
||||||
|
|
||||||
$this->Task->interactive = false;
|
$this->Task->interactive = false;
|
||||||
|
|
||||||
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
|
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
|
||||||
$this->Task->params['output'] = $path . DS;
|
$this->Task->params['output'] = $this->path . DS;
|
||||||
$this->Task->expects($this->never())->method('err');
|
$this->Task->expects($this->never())->method('err');
|
||||||
$this->Task->expects($this->any())->method('in')
|
$this->Task->expects($this->any())->method('in')
|
||||||
->will($this->returnValue('y'));
|
->will($this->returnValue('y'));
|
||||||
$this->Task->expects($this->never())->method('_stop');
|
$this->Task->expects($this->never())->method('_stop');
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
$this->assertTrue(file_exists($path . DS . 'default.pot'));
|
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
|
||||||
$result = file_get_contents($path . DS . 'default.pot');
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
||||||
|
|
||||||
$pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
|
$pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
@ -131,7 +133,7 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
|
||||||
// extract.ctp - reading the domain.pot
|
// extract.ctp - reading the domain.pot
|
||||||
$result = file_get_contents($path . DS . 'domain.pot');
|
$result = file_get_contents($this->path . DS . 'domain.pot');
|
||||||
|
|
||||||
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
||||||
$this->assertNoPattern($pattern, $result);
|
$this->assertNoPattern($pattern, $result);
|
||||||
|
@ -142,9 +144,32 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
}
|
||||||
|
|
||||||
$Folder = new Folder($path);
|
/**
|
||||||
$Folder->delete();
|
* test exclusions
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testExtractWithExclude() {
|
||||||
|
$this->Task->interactive = false;
|
||||||
|
|
||||||
|
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views';
|
||||||
|
$this->Task->params['output'] = $this->path . DS;
|
||||||
|
$this->Task->params['exclude'] = 'pages,layouts';
|
||||||
|
|
||||||
|
$this->Task->expects($this->any())->method('in')
|
||||||
|
->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
$this->Task->execute();
|
||||||
|
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
|
||||||
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
||||||
|
|
||||||
|
$pattern = '/\#: .*extract\.ctp:6\n/';
|
||||||
|
$this->assertNotRegExp($pattern, $result);
|
||||||
|
|
||||||
|
$pattern = '/\#: .*default\.ctp:26\n/';
|
||||||
|
$this->assertNotRegExp($pattern, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,21 +178,18 @@ class ExtractTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testExtractMultiplePaths() {
|
function testExtractMultiplePaths() {
|
||||||
$path = TMP . 'tests' . DS . 'extract_task_test';
|
|
||||||
new Folder($path . DS . 'locale', true);
|
|
||||||
|
|
||||||
$this->Task->interactive = false;
|
$this->Task->interactive = false;
|
||||||
|
|
||||||
$this->Task->params['paths'] =
|
$this->Task->params['paths'] =
|
||||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages,' .
|
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages,' .
|
||||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'posts';
|
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'posts';
|
||||||
|
|
||||||
$this->Task->params['output'] = $path . DS;
|
$this->Task->params['output'] = $this->path . DS;
|
||||||
$this->Task->expects($this->never())->method('err');
|
$this->Task->expects($this->never())->method('err');
|
||||||
$this->Task->expects($this->never())->method('_stop');
|
$this->Task->expects($this->never())->method('_stop');
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
$result = file_get_contents($path . DS . 'default.pot');
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
||||||
|
|
||||||
$pattern = '/msgid "Add User"/';
|
$pattern = '/msgid "Add User"/';
|
||||||
$this->assertPattern($pattern, $result);
|
$this->assertPattern($pattern, $result);
|
||||||
|
|
Loading…
Add table
Reference in a new issue