• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inflector helper -> plural()

#1
[eluser]Jonathon Hill[/eluser]
I was using the inflect() function to pluralize "day" and got "daies." Yuck!

The bug actually exists in plural(). Here's a fix:

Code:
function plural($str, $force = FALSE)
{
    $str = strtolower(trim($str));
    $end = substr($str, -1);

    if ($end == 'y')
    {
        $dipthongs = array('ay', 'ey', 'iy', 'oy', 'uy');
        $str = (!in_array(substr($str, -2), $dipthongs))? substr($str, 0, strlen($str)-1).'ies' : $str .= 's';
    }
    elseif ($end == 's')
    {
        if ($force == TRUE)
        {
            $str .= 'es';
        }
    }
    else
    {
        $str .= 's';
    }

    return $str;
}

Plural of "boy" is "boys", not "boies".
Plural of "ray" is "rays", not "raies".

Are there other dipthongs we need to make exceptions for besides "ay" and "oy"?

#2
[eluser]Michael Wales[/eluser]
Excellent find Jonathon - once you're confident in your solution could you post the bug (and fix) to the Bug Tracker? I'll go ahead and mark that as a Confirmed bug so we can get it fixed in the next release.

#3
[eluser]Jonathon Hill[/eluser]
Thanks Michael!

http://codeigniter.com/bug_tracker/bug/6342/

#4
[eluser]Michael Wales[/eluser]
Marked as confirmed.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.