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.
<p>
{$plural(count, {
one: "# item",
other: "# items",
})}
</p> 2 items
<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.
---import { plural, t } from "lingui-for-astro/macro";
const count = 2;---
<!-- 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>import { plural, t } from "@lingui/core/macro";
// Standaloneconst label: string = plural(count, { one: "# item", other: "# items",});
// Embeddedconst message: string = t`Cart: ${plural(count, { one: "# item", other: "# items",})}`;Exact value match
Section titled “Exact value match”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.
When plural is a good fit
Section titled “When plural is a good fit”- the message depends on a numeric count
- you want official ICU plural behavior
- the function form reads naturally in the current file