Skip to content

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.

Source
<p>
  {name ? $t`Hello ${name}` : $t`Hi there!`}
</p>
Result

Hello Lingui

Locale
Name
<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.

  • 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

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}.