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.
<p>{$t`Hello ${ph({ username: user.profile.displayName })}`}</p>
<p><Trans>Welcome {ph({ username: user.profile.displayName })}!</Trans></p>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.
---import { ph, t, Trans } from "lingui-for-astro/macro";
const user = { name: "Ada" };const greeting = t`Hello ${ph({ username: user.name })}`;---
<p>{greeting}</p><Trans>Welcome {ph({ username: user.name })}!</Trans>import { ph, t } from "@lingui/core/macro";
const greeting = t`Hello ${ph({ username: getUser().name })}`;Extracted message and runtime values
Section titled “Extracted message and runtime values”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, },}Syntax rules
Section titled “Syntax rules”- 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, oritemCount.
When ph is a good fit
Section titled “When ph is a good fit”- 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