Skip to content

plural

plural is the Core Macro for ICU plural messages. There is also a Component Macro form of the same logic, Plural.

Use it when the main problem is choosing text from plural categories. It can be used directly to produce a translated string, or embedded inside a t`...` template literal when the plural belongs to a larger message.

For the framework-agnostic Lingui semantics, see the official plural reference.

Source
<p>
  {$plural(count, {
    one: "# item",
    other: "# items",
  })}
</p>
Result

2 items

Locale
Count
<script lang="ts">
import { plural, t } from "lingui-for-svelte/macro";
let count = $state(2);
</script>
<!-- Standalone: produces the plural string directly. -->
<p>
{$plural(count, {
one: "# item",
other: "# items",
})}
</p>
<!-- Embedded: plural is part of a larger translated unit. -->
<p>
{$t`Cart: ${plural(count, {
one: "# item",
other: "# items",
})}`}
</p>

In .svelte files, use $plural for reactive standalone use. When nested inside $t`...`, use plural without the $ prefix.

See Reactive Macros for the full explanation, including the plural.eager escape hatch.

Use a plain numeric key to match an exact count. Exact matches take precedence over category keys.

plural(count, {
0: "No items",
one: "# item",
other: "# items",
});

The component macro Plural expresses the same match with an underscore-prefixed prop (_0="No items"). The function form uses a plain number key; no underscore is needed.

  • the message depends on a numeric count
  • you want official ICU plural behavior
  • the function form reads naturally in the current file