From a324348be2e5eb54643c7661310f52e999cf00a3 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sun, 18 Feb 2007 13:10:11 +0000 Subject: [PATCH] Adding fix for #2068. Renaming Translate to TranslateBehavior. Added empty class methods to TranslateBehavior. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4533 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/inflector.php | 24 ++++++----- cake/libs/model/behaviors/translate.php | 52 +++++++++++------------- cake/tests/cases/libs/inflector.test.php | 12 +++--- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index d93e9c769..ab58215eb 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -74,6 +74,7 @@ class Inflector extends Object { function __initPluralRules() { $_this =& Inflector::getInstance(); $corePluralRules = array('/(s)tatus$/i' => '\1\2tatuses', + '/(quiz)$/i' => '\1zes', '/^(ox)$/i' => '\1\2en', # ox '/([m|l])ouse$/i' => '\1ice', # mouse, louse '/(matr|vert|ind)ix|ex$/i' => '\1ices', # matrix, vertex, index @@ -118,6 +119,7 @@ class Inflector extends Object { 'hoof' => 'hoofs', 'loaf' => 'loaves', 'man' => 'men', + 'menu' => 'menus', 'money' => 'monies', 'mongoose' => 'mongooses', 'move' => 'moves', @@ -173,16 +175,16 @@ class Inflector extends Object { $_this->pluralRules['regexIrregular'] = $regexIrregular; } - if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) { - $_this->pluralized[$word] = $word; - return $word; - } - if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) { $_this->pluralized[$word] = $regs[1] . $irregular[strtolower($regs[2])]; return $_this->pluralized[$word]; } + if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) { + $_this->pluralized[$word] = $word; + return $word; + } + foreach($pluralRules as $rule => $replacement) { if (preg_match($rule, $word)) { $_this->pluralized[$word] = preg_replace($rule, $replacement, $word); @@ -202,6 +204,7 @@ class Inflector extends Object { $_this =& Inflector::getInstance(); $coreSingularRules = array('/(s)tatuses$/i' => '\1\2tatus', + '/(quiz)zes$/i' => '\\1', '/(matr)ices$/i' => '\1ix', '/(vert|ind)ices$/i' => '\1ex', '/^(ox)en/i' => '\1', @@ -254,6 +257,7 @@ class Inflector extends Object { 'hoofs' => 'hoof', 'loaves' => 'loaf', 'men' => 'man', + 'menus' => 'menu', 'monies' => 'money', 'mongooses' => 'mongoose', 'moves' => 'move', @@ -309,16 +313,16 @@ class Inflector extends Object { $_this->singularRules['regexIrregular'] = $regexIrregular; } - if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) { - $_this->singularized[$word] = $word; - return $word; - } - if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) { $_this->singularized[$word] = $regs[1] . $irregular[strtolower($regs[2])]; return $_this->singularized[$word]; } + if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) { + $_this->singularized[$word] = $word; + return $word; + } + foreach($singularRules as $rule => $replacement) { if (preg_match($rule, $word)) { $_this->singularized[$word] = preg_replace($rule, $replacement, $word); diff --git a/cake/libs/model/behaviors/translate.php b/cake/libs/model/behaviors/translate.php index b34223396..d9af9574e 100644 --- a/cake/libs/model/behaviors/translate.php +++ b/cake/libs/model/behaviors/translate.php @@ -19,59 +19,55 @@ * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @package cake - * @subpackage cake.cake.libs.model.i18n - * @since CakePHP(tm) v 1.2.0.3995 + * @subpackage cake.cake.libs.model.behaviors + * @since CakePHP(tm) v 1.2.0.4525 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ +/** + * Included libraries. + */ +uses('l10n'); /** * Short description for file. * * Long description for file * * @package cake - * @subpackage cake.cake.libs.model.i18n - * @since CakePHP v 1.2.0.3995 + * @subpackage cake.cake.libs.model.behaviors * */ -class Translate extends AppModel { +class TranslateBehavior extends ModelBehavior { var $locale = null; - function read ($id = null, $fields = null) { - $result = parent::read($id, $fields); - return $result; + function setup(&$model, $config = array()) { + } - function field ($name, $conditions = null, $order = null) { - $result = parent::field ($name, $conditions, $order); - return $result; + function beforeFind(&$model, $query) { + } - function saveField($name, $value, $validate = false) { - $result = parent::saveField($name, $value, $validate ); - return $result; + function afterFind(&$model, $results, $primary) { + } - function save ($data=null, $validate=true) { - $result = parent::save ($data, $validate); - return $result; + function beforeSave(&$model) { + } - function del ($id = null) { - $result = parent::del($id); - return $result; + function afterSave(&$model, $created) { + } - function find ($conditions = null, $fields = null, $order = null, $recursive = 1) { - $result = parent::find($conditions , $fields , $order , $recursive); - return $result; - } + function beforeDelete(&$model) { - function findAll ($conditions = null, $fields = null, $order = null, $limit = 50, $page = 1, $recursive = 1) { - $result = parent::findAll($conditions , $fields , $order , $limit , $page , $recursive); - return $result; - } + } + + function afterDelete(&$model) { + + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index fe631a62a..4a541026d 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -43,29 +43,29 @@ class InflectorTest extends UnitTestCase { function testInflectingSingulars() { $result = $this->inflector->singularize('menus'); $expected = 'menu'; - $this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); + $this->assertEqual($result, $expected); $result = $this->inflector->singularize('quizzes'); $expected = 'quiz'; - $this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); + $this->assertEqual($result, $expected); } function testInflectingPlurals() { $result = $this->inflector->pluralize('Bus'); $expected = 'Buses'; - $this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); + $this->assertEqual($result, $expected); $result = $this->inflector->pluralize('bus'); $expected = 'buses'; - $this->assertEqual($this->inflector->pluralize('bus'), 'buses', "Badness! Expected '{$expected}', got '{$result}'"); + $this->assertEqual($result, $expected); $result = $this->inflector->pluralize('menu'); $expected = 'menus'; - $this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); + $this->assertEqual($result, $expected); $result = $this->inflector->pluralize('quiz'); $expected = 'quizzes'; - $this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); + $this->assertEqual($result, $expected); } function tearDown() {