t
t is Lingui’s primary string-producing macro. It translates a message at the call site and returns
the resulting string.
Use t when you want a translated label, heading, or piece of inline text and you do not need
embedded markup. For rich text with links or emphasis, use the Trans Component Macro instead.
For the framework-agnostic Lingui semantics, see the
official t reference.
<p>
{name ? $t`Hello ${name}` : $t`Hi there!`}
</p>Hello Lingui
<script lang="ts"> import { t } from "lingui-for-svelte/macro";
let name = $state("Lingui");</script>
<p>{$t`Hello ${name}`}</p>In .svelte files, use $t. It re-evaluates automatically when the active locale changes. Bare
t (without $) is a compile-time error.
See Reactive Macros for how this works, when to use
$derived, and the t.eager escape hatch.
---import { t } from "lingui-for-astro/macro";
const name = "Lingui";---
<p>{t`Hello ${name}`}</p>In .astro, t is request-bound and non-reactive.
import { t } from "@lingui/core/macro";
const name = "Lingui";
const label = t`Hello ${name}`;// -> "Hello Lingui" or the equivalent in the active localeWhen t is a good fit
Section titled “When t is a good fit”- you want a translated string immediately
- the message is naturally authored as text or a string template
- rich text structure is not the main concern
Nesting t and msg
Section titled “Nesting t and msg”With Lingui 6.6 or later, a t or msg tagged template nested inside another core macro is inlined
into the outer message instead of becoming a separate translation call. This also lets you use
msg as a plural or select option when an option needs its own interpolations.
<script lang="ts"> import { msg, plural, t } from "lingui-for-svelte/macro";
let count = $state(1); const books = msg`You have ${plural(count, { 0: msg`No books`, one: msg`One book`, other: "# books", })}`;</script>
<!-- Extracted as "Field First Name is required" --><p>{$t`Field ${$t`First Name`} is required`}</p><p>{$t(books)}</p>The same applies to t in .astro files. With Lingui 6.5 or earlier, the inner macro is translated
separately and the outer message receives it as a positional placeholder such as {0}.