Agent Wranglers

NTF-38Recommended

Write each notification in the recipient's language

Render every notification in the language stored for the recipient. Never use the language of the person or the request that caused it.

How to do it

When a Swedish user comments on a post, its author may read German. Store a language tag per user, such as de or sv-SE, set as Let people pick their language says. Render at send time with that tag and the app's own message catalogue. Translate whole sentences with plural rules, as Get plurals right in every language says. Native apps can instead send string keys, such as loc-key for APNs or body_loc_key for FCM, so the phone picks its own language. Fall back to the default language when no tag is stored.

Examples

JavaScript example

export function renderFor(recipient, typeId, values) {
  const locale = recipient.locale ?? DEFAULT_LOCALE;
  const template = MESSAGES[locale]?.[typeId] ?? MESSAGES[DEFAULT_LOCALE][typeId];
  return template(values, new Intl.PluralRules(locale));
}

Python example

from babel.support import Translations

def render_for(recipient, type_id: str, values: dict) -> str:
    locale = recipient.locale or DEFAULT_LOCALE
    translations = Translations.load("locales", [locale])
    return translations.gettext(type_id).format(**values)

How to check

A test lets a Swedish user trigger a notification to a German user, and the rendered text is the German template. A second test fails if any notification template lacks a translation in a supported language.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/notifications/channels-and-preferences/recipient-language">Agent Wranglers notifications playbook</a>. In code you write, add a comment next to it with the same link.