You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using pluralise or singularise, developers are required to add if/else logic to determine which function to use. I borrowed some logic from CFWeels which has a Pluralize() function that accepts two additional parameters: count and returnCount. I've added these to the inflector CFC that we use and am sharing it in case anyone else is interested.
<cffunctionname="pluralise" access="public" returntype="string" output="no" hint="Returns the plural form of a word"><cfargumentname="word" type="string" required="yes" hint="The word to get the plural for"><cfargumentname="count" type="numeric" required="no" default="-1" hint="Pluralization will occur when this value is not 1."><cfargumentname="returnCount" type="boolean" required="no" default="false" hint="Will return count prepended to the pluralization when true and count is not -1."><cfsetvari = 0><cfifarguments.countNEQ-1andarguments.countEQ1><cfsetarguments.word = singularise(arguments.word)><cfelse><cfifNOTlistfind(variables.uncountables,lcase(arguments.word))><cfloopfrom="1" to="#arraylen(variables.plurals)#" index="i"><cfifrefindnocase(variables.plurals[i]['rule'], arguments.word)><cfsetarguments.word = rereplacenocase(arguments.word,variables.plurals[i]['rule'], variables.plurals[i]['replacement'])><cfbreak></cfif></cfloop></cfif></cfif><cfifarguments.countNEQ-1andarguments.returnCount><cfsetarguments.word = NumberFormat(arguments.count)& " " & arguments.word></cfif><cfreturnarguments.word></cffunction>
I've also added support for calling it as pluralize (with a z) since that's the way it's spelled in our region.
<cfsetpluralize = pluralise>
The text was updated successfully, but these errors were encountered:
When using
pluralise
orsingularise
, developers are required to addif/else
logic to determine which function to use. I borrowed some logic from CFWeels which has a Pluralize() function that accepts two additional parameters:count
andreturnCount
. I've added these to the inflector CFC that we use and am sharing it in case anyone else is interested.I've also added support for calling it as
pluralize
(with az
) since that's the way it's spelled in our region.The text was updated successfully, but these errors were encountered: