Skip to content

Global Helpers

pluralize()

pluralize() — returns string

Available in: controller, model, 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
wordstringyes—The 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. Pluralize a word using standard rules
writeOutput(pluralize("person"));
// -> "people"

// 2. Pluralize based on a count; returns count prepended to the word
writeOutput(pluralize(word="comment", count=1));
// -> "1 comment"

writeOutput(pluralize(word="comment", count=5));
// -> "5 comments"

// 3. Pluralize based on a count but omit the count from the output
writeOutput(pluralize(word="person", count=users.RecordCount, returnCount=false));
// -> "people" (when RecordCount != 1) or "person" (when RecordCount == 1)