22972 Posts in 11596 Topics by 2824 members
|Go to End|
6 January 2014 at 10:49pm
There is a method on DataObject which returns a 'best guess' plural name of you data object, see - http://api.silverstripe.org/3.0/source-class-DataObject.html#659-676
$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';
return ucfirst($name . 's');
This is used by GridFields 'Link Existing' auto completer. I am confused by the nested if() in this method. I understand the purpose of truncating a 'y' and replacing with 'ies' e.g. Party -> Parties etc.
The first part of the if() checks to see if the name ends with 'e', if so it truncates it (and then proceeds to make it plural by adding 's')!
I cannot think of any good reason for this? Perhaps I am missing something but I do not see why this line of code exists? It is returning 'Carousel Slids' instread of 'Carousel Slides' for one of my data objects. Other incorrect examples it would return include:
- Tree = Tres
- Page = Pags
- Attribute = Attributs
I know I can solve this issue by adding a 'private static $plural_name = "Carousel Slides";' on my data object, but thats not the point, I am trying to understand if there is any logical reason for this line of code, or if it should be marked as a bug?
Any suggestions appreciated.
7 January 2014 at 12:41am
Interesting I can see how this wouldn't work at all for other locales besides en_US !
I'm all for just returning the singular name, that is at least a valid name, even if not syntactically correct in the context. And maybe update the documentation about the importance of setting your own plural_name?
7 January 2014 at 1:33am
Thanks for the reply Martimiz,
Out of pure curiosity can you give me some examples of how this does work for words in en_US locale?
I'm just trying to work out how truncating the 'e' is beneficial in any locale and am struggling to come up with any examples where it works?
7 January 2014 at 2:33am
haha - no! I meant to agree with you on the e, and then go even further by saying that replacing an y for an ie might not always be a good idea in, say, Dutch
|Go to Top|