Skip to content

Commit

Permalink
Fix I18n to extract plugin model validation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rchavik committed Jul 7, 2013
1 parent 481d392 commit 4bb0a12
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
26 changes: 22 additions & 4 deletions lib/Cake/Console/Command/Task/ExtractTask.php
Expand Up @@ -441,11 +441,29 @@ protected function _extractValidationMessages() {
return;
}

$plugins = array(null);
if (empty($this->params['exclude-plugins'])) {
$plugins = array_merge($plugins, App::objects('plugins'));
}
foreach ($plugins as $plugin) {
$this->_extractPluginValidationMessages($plugin);
}
}

/**
* Extract validation messages from application or plugin models
*
* @param string $plugin Plugin name or `null` to process application models
* @return void
*/
protected function _extractPluginValidationMessages($plugin = null) {
App::uses('AppModel', 'Model');
$plugin = null;
if (!empty($this->params['plugin'])) {
App::uses($this->params['plugin'] . 'AppModel', $this->params['plugin'] . '.Model');
$plugin = $this->params['plugin'] . '.';
if (!empty($plugin)) {
if (!CakePlugin::loaded($plugin)) {
return;
}
App::uses($plugin . 'AppModel', $plugin . '.Model');
$plugin = $plugin . '.';
}
$models = App::objects($plugin . 'Model', null, false);

Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php
Expand Up @@ -268,7 +268,7 @@ public function testExtractPlugin() {
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ExtractTask',
array('_isExtractingApp', '_extractValidationMessages', 'in', 'out', 'err', 'clear', '_stop'),
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
array($this->out, $this->out, $this->in)
);

Expand All @@ -280,6 +280,7 @@ public function testExtractPlugin() {
$this->assertNotRegExp('#Pages#', $result);
$this->assertContains('translate.ctp:1', $result);
$this->assertContains('This is a translatable string', $result);
$this->assertContains('I can haz plugin model validation message', $result);
}

/**
Expand Down
Expand Up @@ -32,4 +32,13 @@ class TestPluginAuthors extends TestPluginAppModel {

public $name = 'TestPluginAuthors';

public $validate = array(
'field' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'I can haz plugin model validation message',
),
),
);

}

0 comments on commit 4bb0a12

Please sign in to comment.