Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing a new option 'exclude-plugins' from the ExtractTask
- Loading branch information
Showing
3 changed files
with
66 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,7 @@ public function execute() { | |
if (isset($this->params['paths'])) { | ||
$this->_paths = explode(',', $this->params['paths']); | ||
} else { | ||
$defaultPath = APP_PATH; | ||
$defaultPath = APP; | ||
$message = __d('cake_console', "What is the path you would like to extract?\n[Q]uit [D]one"); | ||
while (true) { | ||
$response = $this->in($message, null, $defaultPath); | ||
|
@@ -133,6 +133,10 @@ public function execute() { | |
} | ||
} | ||
|
||
if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) { | ||
$this->_exclude = array_merge($this->_exclude, App::path('plugins')); | ||
} | ||
|
||
if (isset($this->params['output'])) { | ||
$this->_output = $this->params['output']; | ||
} else { | ||
|
@@ -208,39 +212,24 @@ public function getOptionParser() { | |
)) | ||
->addOption('output', array('help' => __d('cake_console', 'Full path to output directory.'))) | ||
->addOption('files', array('help' => __d('cake_console', 'Comma separated list of files.'))) | ||
->addOption('exclude-plugins', array( | ||
'boolean' => true, | ||
'default' => true, | ||
'help' => __d('cake_console', 'Ignores all files in plugins.') | ||
)) | ||
->addOption('ignore-model-validation', array( | ||
'boolean' => true, | ||
'default' => false, | ||
'help' => __d('cake_console', 'Ignores validation messages in the $validate property. Needs to be run in from the same app directory') | ||
)) | ||
->addOption('validation-domain', array( | ||
'help' => __d('cake_console', 'If set to a value, the localization domain to be used for model validation messages') | ||
)) | ||
->addOption('exclude', array( | ||
'help' => __d('cake_console', 'Comma separated list of directories to exclude. Any path containing a path segment with the provided values will be skipped. E.g. test,vendors') | ||
)); | ||
} | ||
|
||
/** | ||
* Show help options | ||
* | ||
* @return void | ||
*/ | ||
public function help() { | ||
$this->out(__d('cake_console', 'CakePHP Language String Extraction:')); | ||
$this->hr(); | ||
$this->out(__d('cake_console', 'The Extract script generates .pot file(s) with translations')); | ||
$this->out(__d('cake_console', 'By default the .pot file(s) will be place in the locale directory of -app')); | ||
$this->out(__d('cake_console', 'By default -app is ROOT/app')); | ||
$this->hr(); | ||
$this->out(__d('cake_console', 'Usage: cake i18n extract <command> <param1> <param2>...')); | ||
$this->out(); | ||
$this->out(__d('cake_console', 'Params:')); | ||
$this->out(__d('cake_console', ' -app [path...]: directory where your application is located')); | ||
$this->out(__d('cake_console', ' -root [path...]: path to install')); | ||
$this->out(__d('cake_console', ' -core [path...]: path to cake directory')); | ||
$this->out(__d('cake_console', ' -paths [comma separated list of paths]')); | ||
$this->out(__d('cake_console', ' -merge [yes|no]: Merge all domains strings into the default.pot file')); | ||
$this->out(__d('cake_console', ' -output [path...]: Full path to output directory')); | ||
$this->out(__d('cake_console', ' -files: [comma separated list of files]')); | ||
$this->out(); | ||
$this->out(__d('cake_console', 'Commands:')); | ||
$this->out(__d('cake_console', ' cake i18n extract help: Shows this help message.')); | ||
$this->out(); | ||
} | ||
|
||
/** | ||
* Extract tokens out of all files to be processed | ||
* | ||
|
@@ -524,7 +513,14 @@ protected function _markerError($file, $line, $marker, $count) { | |
protected function _searchFiles() { | ||
$pattern = false; | ||
if (!empty($this->_exclude)) { | ||
$pattern = '/[\/\\\\]' . implode('|', $this->_exclude) . '[\/\\\\]/'; | ||
$exclude = array(); | ||
foreach ($this->_exclude as $e) { | ||
if ($e[0] !== DS) { | ||
$e = DS . $e; | ||
} | ||
$exclude[] = preg_quote($e, '/'); | ||
} | ||
$pattern = '/' . implode('|', $exclude) . '/'; | ||
} | ||
foreach ($this->_paths as $path) { | ||
$Folder = new Folder($path); | ||
|
@@ -540,4 +536,14 @@ protected function _searchFiles() { | |
$this->_files = array_merge($this->_files, $files); | ||
} | ||
} | ||
|
||
/** | ||
* Returns whether this execution is meant to extract string only from directories in folder represented by the | ||
* APP constant, i.e. this task is extracting strings from same application. | ||
* | ||
* @return boolean | ||
*/ | ||
protected function _isExtractingApp() { | ||
return $this->_paths === array(APP); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ADmad
Member
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
lib/Cake/Test/test_app/Plugin/TestPlugin/View/Elements/translate.ctp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php __('This is a translatable string'); ?> |
This is a poor criterium as it fails if trailing slashes are different or _paths includes more than the app. A more eleborate solution is needed, as this leads to silently disabling validation error message extraction.