plural

Pluralize a string.

len $fish | plural "one anchovy" "many anchovies"

In the above, if the length of the string is 1, the first argument will be printed (one anchovy). Otherwise, the second argument will be printed (many anchovies).

The arguments are:

  • singular string
  • plural string
  • length integer

NOTE: Sprig does not currently support languages with more complex pluralization rules. And 0 is considered a plural because the English language treats it as such (zero anchovies). The Sprig developers are working on a solution for better internationalization.

Back to top