selectOrdinal
selectOrdinal is the Core Macro for ICU ordinal-selection messages. There is also a Component Macro form of the same logic, SelectOrdinal.
Use it when the message depends on ordinal categories like 1st, 2nd, or 3rd. It can be used
directly to produce a translated string, or embedded inside a t`...` template literal when
the ordinal belongs to a larger message.
For the framework-agnostic Lingui semantics, see the
official selectOrdinal reference.
<p>
{$selectOrdinal(place, {
one: "#st",
two: "#nd",
few: "#rd",
other: "#th",
})}
</p> 2nd
<script lang="ts"> import { selectOrdinal, t } from "lingui-for-svelte/macro";
let place = $state(2);</script>
<!-- Standalone: produces the ordinal string directly. --><p> {$selectOrdinal(place, { one: "#st", two: "#nd", few: "#rd", other: "#th", })}</p>
<!-- Embedded: selectOrdinal is part of a larger translated unit. --><p> {$t`Ranked ${selectOrdinal(place, { one: "#st", two: "#nd", few: "#rd", other: "#th", })}`}</p>In .svelte files, use $selectOrdinal for reactive standalone use. When nested inside
$t`...`, use selectOrdinal without the $ prefix.
See Reactive Macros for the full explanation, including the
selectOrdinal.eager escape hatch.
---import { selectOrdinal, t } from "lingui-for-astro/macro";
const place = 2;---
<!-- Standalone: produces the ordinal string directly. --><p> { selectOrdinal(place, { one: "#st", two: "#nd", few: "#rd", other: "#th", }) }</p>
<!-- Embedded: selectOrdinal is part of a larger translated unit. --><p> { t`Ranked ${selectOrdinal(place, { one: "#st", two: "#nd", few: "#rd", other: "#th", })}` }</p>import { selectOrdinal, t } from "@lingui/core/macro";
// Standaloneconst label: string = selectOrdinal(place, { one: "#st", two: "#nd", few: "#rd", other: "#th",});
// Embeddedconst message: string = t`Ranked ${selectOrdinal(place, { one: "#st", two: "#nd", few: "#rd", other: "#th",})}`;Exact value match
Section titled “Exact value match”Use a plain numeric key to match an exact value. Exact matches take precedence over category keys.
selectOrdinal(place, { 1: "1st", 2: "2nd", 3: "3rd", other: "#th",});The component macro SelectOrdinal expresses the same match
with an underscore-prefixed prop (_1="1st"). The function form uses a plain number key; no
underscore is needed.
When selectOrdinal is a good fit
Section titled “When selectOrdinal is a good fit”- the output depends on ordinal categories
- the function form is easier to read than component props in the current file
- you want descriptor semantics consistent with official Lingui Core