Skip to content

Plural

Plural is the Component Macro counterpart to the core plural macro.

It represents the same ICU plural logic, but authored as component props in markup. This is useful when the surrounding file is already template-heavy and the component form is easier to scan than a function call.

Standard ICU plural categories (zero, one, two, few, many, other) are used as plain prop names. Exact-value matches use an underscore-prefixed number: _0="No items" matches exactly when value is 0, taking precedence over the category-based props.

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

Source
<p>
  <Plural value={count} one="# file" other="# files" />
</p>
Result

3 files

Locale
Count
<script lang="ts">
import { Plural } from "lingui-for-svelte/macro";
let count = $state(3);
</script>
<Plural value={count} one="# file" other="# files" />

Prefix a number with _ to match an exact value. Exact matches take precedence over category props.

<Plural value={count} _0="No files" one="# file" other="# files" />

The function form uses a plain numeric key for the same effect:

<p>{$plural(count, { 0: 'No files', one: '# file', other: '# files' })}</p>
  • you are already writing markup and want the plural branches inline there
  • the component form is clearer to read than plural(...)
  • you want the same plural semantics as the core macro