LOC-40Recommended
Translate every part of an email
Render the subject, preview text, sender name, HTML part, plain-text part and footer of each email in the recipient's stored language. The links in it open pages in that language.
How to do it
Pick the language as Write each notification in the recipient's language says, at send time, from the recipient's settings. A translated body under an English subject still looks like spam to many readers. Keep every part in the message files, including the unsubscribe text. Add the language prefix to links, as Give each language its own path says. Mark the language in the message as Declare the language and text direction says. Format dates with the recipient's locale and time zone.
Examples
JavaScript example
export function renderEmail(templateId, recipient, values) {
const t = messagesFor(recipient.locale);
return {
subject: t(`${templateId}.subject`, values),
preview: t(`${templateId}.preview`, values),
html: renderHtml(templateId, t, { ...values, baseUrl: `https://example.com/${recipient.locale}` }),
text: renderText(templateId, t, values),
headers: { 'Content-Language': recipient.locale },
};
}
Python example
def render_email(template_id: str, recipient, values: dict) -> dict:
t = messages_for(recipient.locale)
base_url = f"https://example.com/{recipient.locale}"
return {
"subject": t(f"{template_id}.subject").format(**values),
"html": render_html(template_id, t, {**values, "base_url": base_url}),
"text": render_text(template_id, t, values),
"headers": {"Content-Language": recipient.locale},
}
How to check
A test sends each email template to a German test recipient. The subject, preview text, both bodies and the footer contain no source-language message, and every link to your own site starts with /de/.
Related rules
- NTF-38 Write each notification in the recipient's language in Notifications
- LOC-1 Give each language its own path in Localization
- EML-5 Declare the language and text direction in Email
- LOC-22 Store language and time zone as two separate settings in Localization
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/localization/email-notifications-and-ai/localized-email">Agent Wranglers localization playbook</a>. In code you write, add a comment next to it with the same link.