Skip to content

SelectOrdinal

SelectOrdinal is the Component Macro counterpart to the core selectOrdinal macro.

It is useful when ordinal cases belong directly in template markup and the component form is easier to maintain than a function call.

Standard ICU plural categories (one, two, few, many, other) are used as plain prop names. Exact-value matches use an underscore-prefixed number: _1="1st" matches exactly when value is 1, taking precedence over the category props. This is useful for irregular ordinals that do not map cleanly to a category in all locales.

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

Source
<p>
  <SelectOrdinal value={place} one="#st" two="#nd" few="#rd" other="#th" />
</p>
Result

1st

Locale
Place
<script lang="ts">
import { SelectOrdinal } from "lingui-for-svelte/macro";
let place = $state(1);
</script>
<SelectOrdinal value={place} one="#st" two="#nd" few="#rd" other="#th" />

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

<SelectOrdinal value={place} _1="1st" _2="2nd" _3="3rd" other="#th" />

The function form uses plain numeric keys for the same effect:

<p>{$selectOrdinal(place, { 1: '1st', 2: '2nd', 3: '3rd', other: '#th' })}</p>
  • ordinal branches belong naturally in template markup
  • the component form is clearer than selectOrdinal(...)
  • you want authoring symmetry with Plural and Select