Docs (4.0.0)
interface I18nProvider method

getPlural

A method that’s used to choose a plural form based on a specific quantity.

getPlural(n: number, forms: string[]): string

Summary

This method is called primarily by LazyString (the result of strf()), for each plural form placeholder in a format string. The implementation of this method must return one of the plural forms from a list, based on the provided quantity. E.g. for the English language, plural forms may be ["email", "emails"] or simply ["", "s"], where the first one should be chosen if the quantity is exactly 1, otherwise the second form. Other languages may require more than 2 plural forms and/or different rules to pick the correct form.

Parameters

  • n — The quantity on which to base the plural form
  • forms — The list of plural forms from which to choose

Example

// Part of an I18nProvider implementation:
getPlural(n: number, forms: string[]): string {
  return forms[n == 1 ? 0 : 1] || "";
}

Related