Browse Source

Fix I18n to extract plugin model validation messages

Rachman Chavik 12 years ago
parent
commit
4bb0a1228a

+ 22 - 4
lib/Cake/Console/Command/Task/ExtractTask.php

@@ -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);
 

+ 2 - 1
lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php

@@ -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);
 	}
 
 /**

+ 9 - 0
lib/Cake/Test/test_app/Plugin/TestPlugin/Model/TestPluginAuthors.php

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