Skip to content

ph

ph assigns an explicit name to a message placeholder. It is useful when an interpolation is a property access, function call, or other complex expression that would otherwise receive a numeric placeholder such as {0}.

The key gives translators a meaningful placeholder name, while the value remains the expression evaluated at runtime.

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

Source
<p>{$t`Hello ${ph({ username: user.profile.displayName })}`}</p>
<p><Trans>Welcome {ph({ username: user.profile.displayName })}!</Trans></p>
Result

Hello Lingui

Welcome Lingui!

Locale
Name
<script lang="ts">
import { ph, t, Trans } from "lingui-for-svelte/macro";
let user = $state({ name: "Ada" });
</script>
<p>{$t`Hello ${ph({ username: user.name })}`}</p>
<Trans>Welcome {ph({ username: user.name })}!</Trans>

Use ph inside reactive $t expressions or component macros. For an intentional non-reactive script snapshot, the same placeholder syntax works inside t.eager.

Given this source:

t`Hello ${ph({ username: user.name })}`;

the catalog receives a meaningful ICU placeholder:

Hello {username}

The transform keeps the original expression in the runtime value mapping:

{
message: "Hello {username}",
values: {
username: user.name,
},
}
  • Pass an object with exactly one property to ph.
  • The property key becomes the ICU placeholder name.
  • The property value is evaluated at runtime and stored under that name in values.
  • Keep names stable and descriptive, such as username, startDate, or itemCount.
  • a property access or function call would otherwise become {0}
  • translators need to understand what a placeholder represents
  • a stable placeholder name makes catalog changes and reviews easier to follow