Skip to content

Plurals and selectors

Choose a form based on a quantity or an alternative of the message.

Plurals with Intl.PluralRules

JSON catalog json
{
  "cart": {
    "items": {
      "plural": "total",
      "forms": {
        "=0": "Tu cesta está vacía",
        "one": "{count} elemento en tu cesta",
        "other": "{count} elementos en tu cesta"
      }
    }
  }
}

plural names the numeric argument. An exact match such as =0 is looked up first, then the category of Intl.PluralRules and finally other. The number must be finite.

The runtime passes count to the forms as an alias of that number. When the selector is called total, passing { total: 3 } is enough. If the selector is called count, that same argument is still required.

Alternatives with select

Catalog and call ts
{
  "invitation": {
    "select": "role",
    "forms": {
      "owner": "{name}, puedes administrar el proyecto.",
      "other": "{name}, puedes consultar el proyecto."
    }
  }
}

// In your component:
t('invitation', { role: 'owner', name: 'Meeko' })

The selector is converted to text to look up its form; a value without its own alternative uses other. The parameters used by any of its forms are part of the required contract.

Categories of each language

Languages may need different categories. Arabic uses zero, one, two, few, many and other; the playground catalog includes those forms. Every plural or select structure requires other. The forms contain text.

Try quantities and permissions

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters