Skip to content

Global Helpers

pluralize()

pluralize() — returns string

Available in: controller, model, test, mapper, migrator, migration, tabledefinition Category: String Functions

Returns the plural form of the passed in word. Can also pluralize a word based on a value passed to the count argument. Wheels stores a list of words that are the same in both singular and plural form (e.g. “equipment”, “information”) and words that don’t follow the regular pluralization rules (e.g. “child” / “children”, “foot” / “feet”). Use get(“uncountables”) / set(“uncountables”, newList) and get(“irregulars”) / set(“irregulars”, newList) to modify them to suit your needs.

NameTypeRequiredDefaultDescription
wordstringyesThe word to pluralize.
countnumericno-1Pluralization will occur when this value is not 1.
returnCountbooleannotrueWill return count prepended to the pluralization when true and count is not -1.
1. Basic pluralization
pluralize("person")
<!--- Returns: "people" --->

2. Pluralization with count (count = 1, so singular is returned)
pluralize(word="car", count=1)
<!--- Returns: "1 car" --->

3. Pluralization with count (count = 5, so plural is returned)
pluralize(word="car", count=5)
<!--- Returns: "5 cars" --->

4. Suppressing the count in the result
pluralize(word="dog", count=3, returnCount=false)
<!--- Returns: "dogs" --->

5. Irregular plural (child → children)
pluralize("child")
<!--- Returns: "children" --->

6. Uncountable word stays the same
pluralize("equipment")
<!--- Returns: "equipment" --->

7. With count and uncountable word
pluralize(word="equipment", count=2)
<!--- Returns: "2 equipment" --->