Fixing issue where words ending ay/ey/iy/oy/uy are not pluralised correctly

This commit is contained in:
Daniel Hensby 2015-11-06 14:38:59 +00:00
parent 85654a495f
commit dad3784621
2 changed files with 15 additions and 2 deletions

View File

@ -781,7 +781,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
return $name; return $name;
} else { } else {
$name = $this->singular_name(); $name = $this->singular_name();
if(substr($name,-1) == 'y') $name = substr($name,0,-1) . 'ie'; //if the penultimate character is not a vowel, replace "y" with "ies"
if (preg_match('/[^aeiou]y$/i', $name)) {
$name = substr($name,0,-1) . 'ie';
}
return ucfirst($name . 's'); return ucfirst($name . 's');
} }
} }

View File

@ -26,6 +26,9 @@ class DataObjectTest extends SapphireTest {
'DataObjectTest_Staff', 'DataObjectTest_Staff',
'DataObjectTest_CEO', 'DataObjectTest_CEO',
'DataObjectTest_Fan', 'DataObjectTest_Fan',
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
); );
public function testDb() { public function testDb() {
@ -1341,7 +1344,10 @@ class DataObjectTest extends SapphireTest {
$assertions = array( $assertions = array(
'DataObjectTest_Player' => 'Data Object Test Players', 'DataObjectTest_Player' => 'Data Object Test Players',
'DataObjectTest_Team' => 'Data Object Test Teams', 'DataObjectTest_Team' => 'Data Object Test Teams',
'DataObjectTest_Fixture' => 'Data Object Test Fixtures' 'DataObjectTest_Fixture' => 'Data Object Test Fixtures',
'DataObjectTest_Play' => 'Data Object Test Plays',
'DataObjectTest_Bogey' => 'Data Object Test Bogeys',
'DataObjectTest_Ploy' => 'Data Object Test Ploys',
); );
foreach($assertions as $class => $expectedPluralName) { foreach($assertions as $class => $expectedPluralName) {
@ -1937,5 +1943,9 @@ class DataObjectTest_ExtendedTeamComment extends DataObjectTest_TeamComment {
); );
} }
class DataObjectTest_Play extends DataObject implements TestOnly {}
class DataObjectTest_Ploy extends DataObject implements TestOnly {}
class DataObjectTest_Bogey extends DataObject implements TestOnly {}
DataObjectTest_Team::add_extension('DataObjectTest_Team_Extension'); DataObjectTest_Team::add_extension('DataObjectTest_Team_Extension');