Core macros are the JavaScript-side Lingui macros.
They cover two jobs:
- produce translated strings immediately
- define message descriptors for later translation
In official Lingui, these are t, msg, defineMessage, plural, select, and
selectOrdinal. lingui-for keeps those semantics and adapts them to framework syntax where
necessary.
t
Translate a message immediately and return a string.
<p>{
$t\`Hello \${name}\`
}</p>
msg / defineMessage
Define a descriptor now and translate it later.
<script lang="ts">
let welcome = $derived(msg\`Welcome back, \${name}\`);
</script>
<p>{$t(welcome)}</p>
plural
Pick text from plural categories based on a numeric count.
<p>{
$plural(count, {
one: "# item",
other: "# items",
})
}</p>
select
Switch text by a named case such as tone or status.
<p>{
$select(tone, {
formal: "Welcome",
casual: "Hi",
other: "Hello",
})
}</p>
selectOrdinal
Choose ordinal text such as 1st, 2nd, or 3rd.
<p>{
$selectOrdinal(place, {
one: "#st",
two: "#nd",
few: "#rd",
other: "#th",
})
}</p>
Start with a core macro when:
- the result you need is a string or descriptor
- you are not authoring rich text with embedded markup
- you want behavior that matches official Lingui Core as directly as possible