Localization
Send one notification in several languages and control which translation each user sees.
A notification's contents is keyed by locale. Each user gets the best available
translation when their feed loads. More than one locale needs the Growth plan and up (see
plan features).
{
"audience": { "type": "all" },
"defaultLocale": "en",
"contents": {
"en": { "title": "Scheduled maintenance on Sunday", "body": "Expect up to 10 minutes of downtime." },
"de": { "title": "Wartung am Sonntag", "body": "Rechne mit bis zu 10 Minuten Ausfallzeit." },
"pt-BR": { "title": "Manutenção programada no domingo" }
}
}Rules
- 1 to 50 locales per notification.
- Keys are BCP 47 language tags: a 2 or 3 letter language, optionally followed by
subtags, such as
en,de-AT,pt-BRorzh-Hant-TW. Matching is case-insensitive. - Each locale has its own
title(required, up to 200 characters),body(up to 2,000) andactionLabel(up to 60).actionUrl,imageUrl,categoryanddataare shared by all locales. defaultLocaledefaults to the project's default locale. Ifcontentshas no entry for it, the first locale incontentsbecomes the default.
Which translation a user sees
The feed tries, in order, the requested locale (the locale query parameter, which the
SDKs send from their locale option), then the project user's locale (from their
profile). For each of those it looks for:
- an exact match:
de-AT→de-AT; - the language:
de-AT→de; - a regional sibling:
de-AT→de-DE, orpt→pt-BR.
If none of those exist, it uses the notification's default locale.
Each feed item's locale field tells you which translation was used, which is handy for
formatting dates in the same language as the text.
| Requested | Project user locale | Available | Result |
|---|---|---|---|
de-AT | en | en, de | de (language) |
pt | en, pt-BR | pt-BR (regional sibling) | |
fr-CA | en, fr | fr | |
ja | es | en, de (default en) | en (default) |
Setting the user's locale
- From the SDK: pass the UI language as the SDK's
localeoption. It is sent with every feed request. In React and React Native, changing the provider'slocaleprop reloads the feed in the new language; with the JavaScript client, create a new client. The SDKs don't detect the device or browser language on their own. - On the profile: send
localein the SDK'suserprofile, or set it from your backend withPUT /v1/project-users/{userId}. The profile locale is also available to segments and as{{user.locale}}in templates.
UI strings
The SDKs' built-in strings ("Notifications", "Mark all as read", empty states) are
configured separately through their labels option. Relative times ("5 minutes ago") are
formatted with Intl.RelativeTimeFormat in each item's own locale. See the
SDK pages.