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() { function __initPluralRules() {
$_this =& Inflector::getInstance(); $_this =& Inflector::getInstance();
$corePluralRules = array('/(s)tatus$/i' => '\1\2tatuses', $corePluralRules = array('/(s)tatus$/i' => '\1\2tatuses',
'/(quiz)$/i' => '\1zes',
'/^(ox)$/i' => '\1\2en', # ox '/^(ox)$/i' => '\1\2en', # ox
'/([m|l])ouse$/i' => '\1ice', # mouse, louse '/([m|l])ouse$/i' => '\1ice', # mouse, louse
'/(matr|vert|ind)ix|ex$/i' => '\1ices', # matrix, vertex, index '/(matr|vert|ind)ix|ex$/i' => '\1ices', # matrix, vertex, index
@ -118,6 +119,7 @@ class Inflector extends Object {
'hoof' => 'hoofs', 'hoof' => 'hoofs',
'loaf' => 'loaves', 'loaf' => 'loaves',
'man' => 'men', 'man' => 'men',
'menu' => 'menus',
'money' => 'monies', 'money' => 'monies',
'mongoose' => 'mongooses', 'mongoose' => 'mongooses',
'move' => 'moves', 'move' => 'moves',
@ -173,16 +175,16 @@ class Inflector extends Object {
$_this->pluralRules['regexIrregular'] = $regexIrregular; $_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)) { if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) {
$_this->pluralized[$word] = $regs[1] . $irregular[strtolower($regs[2])]; $_this->pluralized[$word] = $regs[1] . $irregular[strtolower($regs[2])];
return $_this->pluralized[$word]; return $_this->pluralized[$word];
} }
if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) {
$_this->pluralized[$word] = $word;
return $word;
}
foreach($pluralRules as $rule => $replacement) { foreach($pluralRules as $rule => $replacement) {
if (preg_match($rule, $word)) { if (preg_match($rule, $word)) {
$_this->pluralized[$word] = preg_replace($rule, $replacement, $word); $_this->pluralized[$word] = preg_replace($rule, $replacement, $word);
@ -202,6 +204,7 @@ class Inflector extends Object {
$_this =& Inflector::getInstance(); $_this =& Inflector::getInstance();
$coreSingularRules = array('/(s)tatuses$/i' => '\1\2tatus', $coreSingularRules = array('/(s)tatuses$/i' => '\1\2tatus',
'/(quiz)zes$/i' => '\\1',
'/(matr)ices$/i' => '\1ix', '/(matr)ices$/i' => '\1ix',
'/(vert|ind)ices$/i' => '\1ex', '/(vert|ind)ices$/i' => '\1ex',
'/^(ox)en/i' => '\1', '/^(ox)en/i' => '\1',
@ -254,6 +257,7 @@ class Inflector extends Object {
'hoofs' => 'hoof', 'hoofs' => 'hoof',
'loaves' => 'loaf', 'loaves' => 'loaf',
'men' => 'man', 'men' => 'man',
'menus' => 'menu',
'monies' => 'money', 'monies' => 'money',
'mongooses' => 'mongoose', 'mongooses' => 'mongoose',
'moves' => 'move', 'moves' => 'move',
@ -309,16 +313,16 @@ class Inflector extends Object {
$_this->singularRules['regexIrregular'] = $regexIrregular; $_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)) { if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) {
$_this->singularized[$word] = $regs[1] . $irregular[strtolower($regs[2])]; $_this->singularized[$word] = $regs[1] . $irregular[strtolower($regs[2])];
return $_this->singularized[$word]; return $_this->singularized[$word];
} }
if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) {
$_this->singularized[$word] = $word;
return $word;
}
foreach($singularRules as $rule => $replacement) { foreach($singularRules as $rule => $replacement) {
if (preg_match($rule, $word)) { if (preg_match($rule, $word)) {
$_this->singularized[$word] = preg_replace($rule, $replacement, $word); $_this->singularized[$word] = preg_replace($rule, $replacement, $word);

View file

@ -19,59 +19,55 @@
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc. * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake * @package cake
* @subpackage cake.cake.libs.model.i18n * @subpackage cake.cake.libs.model.behaviors
* @since CakePHP(tm) v 1.2.0.3995 * @since CakePHP(tm) v 1.2.0.4525
* @version $Revision$ * @version $Revision$
* @modifiedby $LastChangedBy$ * @modifiedby $LastChangedBy$
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
/**
* Included libraries.
*/
uses('l10n');
/** /**
* Short description for file. * Short description for file.
* *
* Long description for file * Long description for file
* *
* @package cake * @package cake
* @subpackage cake.cake.libs.model.i18n * @subpackage cake.cake.libs.model.behaviors
* @since CakePHP v 1.2.0.3995
* *
*/ */
class Translate extends AppModel { class TranslateBehavior extends ModelBehavior {
var $locale = null; var $locale = null;
function read ($id = null, $fields = null) { function setup(&$model, $config = array()) {
$result = parent::read($id, $fields);
return $result;
} }
function field ($name, $conditions = null, $order = null) { function beforeFind(&$model, $query) {
$result = parent::field ($name, $conditions, $order);
return $result;
} }
function saveField($name, $value, $validate = false) { function afterFind(&$model, $results, $primary) {
$result = parent::saveField($name, $value, $validate );
return $result;
} }
function save ($data=null, $validate=true) { function beforeSave(&$model) {
$result = parent::save ($data, $validate);
return $result;
} }
function del ($id = null) { function afterSave(&$model, $created) {
$result = parent::del($id);
return $result;
} }
function find ($conditions = null, $fields = null, $order = null, $recursive = 1) { function beforeDelete(&$model) {
$result = parent::find($conditions , $fields , $order , $recursive);
return $result;
}
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() { function testInflectingSingulars() {
$result = $this->inflector->singularize('menus'); $result = $this->inflector->singularize('menus');
$expected = 'menu'; $expected = 'menu';
$this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); $this->assertEqual($result, $expected);
$result = $this->inflector->singularize('quizzes'); $result = $this->inflector->singularize('quizzes');
$expected = 'quiz'; $expected = 'quiz';
$this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); $this->assertEqual($result, $expected);
} }
function testInflectingPlurals() { function testInflectingPlurals() {
$result = $this->inflector->pluralize('Bus'); $result = $this->inflector->pluralize('Bus');
$expected = 'Buses'; $expected = 'Buses';
$this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); $this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('bus'); $result = $this->inflector->pluralize('bus');
$expected = 'buses'; $expected = 'buses';
$this->assertEqual($this->inflector->pluralize('bus'), 'buses', "Badness! Expected '{$expected}', got '{$result}'"); $this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('menu'); $result = $this->inflector->pluralize('menu');
$expected = 'menus'; $expected = 'menus';
$this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); $this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('quiz'); $result = $this->inflector->pluralize('quiz');
$expected = 'quizzes'; $expected = 'quizzes';
$this->assertEqual($result, $expected, "Badness! Expected '{$expected}', got '{$result}'"); $this->assertEqual($result, $expected);
} }
function tearDown() { function tearDown() {