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
This commit is contained in:
phpnut 2007-02-18 13:10:11 +00:00
parent 9bf807b2b6
commit a324348be2
3 changed files with 44 additions and 44 deletions

View file

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

View file

@ -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) {
}
}
?>

View file

@ -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() {