Fix I18n to extract plugin model validation messages

This commit is contained in:
Rachman Chavik 2013-07-06 19:58:38 +07:00
parent 481d3920ae
commit 4bb0a1228a
3 changed files with 33 additions and 5 deletions

View file

@ -441,11 +441,29 @@ class ExtractTask extends AppShell {
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);

View file

@ -268,7 +268,7 @@ class ExtractTaskTest extends CakeTestCase {
$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)
);
@ -280,6 +280,7 @@ class ExtractTaskTest extends CakeTestCase {
$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);
}
/**

View file

@ -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',
),
),
);
}