Skip to content

Trans

Trans is the general-purpose Component Macro for translated markup content.

Use Trans when a translator needs to preserve links, emphasis, or other embedded structure. It can also be used for non-rich-text messages, but its clearest advantage shows up when the message is naturally authored as markup. Embedded markup is preserved as structured placeholders, interpolated values remain values instead of being baked into text, and translators can reorder or re-nest those placeholders when the target language reads better that way.

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

Source
<p>
  <Trans>
    Say hello to <strong>{name}</strong>.
  </Trans>
</p>
Result

Say hello to Lingui.

Locale
Name
<script lang="ts">
import { Trans } from "lingui-for-svelte/macro";
</script>
<Trans>
Read the <a href="/docs">documentation</a>.
</Trans>
  • the message includes links, emphasis, or other embedded markup
  • text and markup belong to the same translated sentence
  • translators may need to move or re-nest wrappers in the target language
  • the message reads more naturally as markup than as a string template

lingui-for-svelte and lingui-for-astro both support the common rich-text core:

  • plain text and interpolated values
  • nested HTML and component wrappers
  • self-closing wrappers used as placeholders

Framework-native rich-text holes are also supported:

FeatureSvelteAstro
Raw HTML hole{@html ...}set:html={...}
Render/snippet hole{@render ...}n/a
Text holen/aset:text={...}

The exact set of allowed wrapper syntax depends on the template language.

  • Svelte supports wrapper directives, let:, {@html}, and {@render} inside Trans. See Trans in Svelte.
  • Astro supports class:list, transition:*, client:*, server:*, set:html, and set:text inside Trans. See Trans in Astro.

Some constructs are still intentionally unsupported because they are not wrapper-shaped rich-text content. Examples include block syntax in Svelte and script, style, or is:raw in Astro.

Trans is processed internally through JSX-compatible machinery, but .svelte and .astro templates are not JSX. Because of that, whitespace between child nodes can otherwise be interpreted differently from what the framework would normally do.

By default, lingui-for-svelte and lingui-for-astro use framework-aware whitespace handling for Trans and the other component macros instead of raw JSX semantics.

See Whitespace in Component Macros for the exact rules, configuration, and examples.