mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fixing plural_name messing up singular words ending in "e" (#3251)
This would ideally be fixed with the ability to use an external library like gettext, but that's an API change. This for now fixes the issue where a singular like "Page" returns "Pags" for the plural name.
This commit is contained in:
parent
552b54201a
commit
61c6dee057
@ -713,9 +713,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
return $name;
|
||||
} else {
|
||||
$name = $this->singular_name();
|
||||
if(substr($name,-1) == 'e') $name = substr($name,0,-1);
|
||||
else if(substr($name,-1) == 'y') $name = substr($name,0,-1) . 'ie';
|
||||
|
||||
if(substr($name,-1) == 'y') $name = substr($name,0,-1) . 'ie';
|
||||
return ucfirst($name . 's');
|
||||
}
|
||||
}
|
||||
|
@ -964,6 +964,25 @@ class DataObjectTest extends SapphireTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that plural_name() generates sensible defaults.
|
||||
*/
|
||||
public function testPluralName() {
|
||||
$assertions = array(
|
||||
'DataObjectTest_Player' => 'Data Object Test Players',
|
||||
'DataObjectTest_Team' => 'Data Object Test Teams',
|
||||
'DataObjectTest_Fixture' => 'Data Object Test Fixtures'
|
||||
);
|
||||
|
||||
foreach($assertions as $class => $expectedPluralName) {
|
||||
$this->assertEquals(
|
||||
$expectedPluralName,
|
||||
singleton($class)->plural_name(),
|
||||
"Assert that the plural_name for '$class' is correct."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasDatabaseField() {
|
||||
$team = singleton('DataObjectTest_Team');
|
||||
$subteam = singleton('DataObjectTest_SubTeam');
|
||||
|
Loading…
Reference in New Issue
Block a user