Introduction
Translate transactional emails into any language using AI.
i18n-email translates transactional emails into any language using AI. Pass a React Email component or a raw HTML string, specify a target locale, and get back a translated subject and html — ready to send.
Features
- Works with React Email components or raw HTML strings
- Translates the subject line and full body in a single API call
- Detects the source language automatically — skips translation when already in the target locale
- Skips
<style>,<script>, and<head>— only visible text is extracted and sent - RTL support — injects
dir="rtl"automatically for Arabic, Hebrew, Persian, and Urdu - Optional cache layer with key prefix to avoid redundant API calls
- AI SDK support — use any Vercel AI SDK provider (OpenAI, Anthropic, Google, Mistral, etc.)
How it works
- Render — if a React component is passed, it is rendered to HTML via
@react-email/render - Extract — the HTML is parsed and walked; visible text nodes and translatable attributes (
alt,title) are collected, adjacent sibling text nodes are merged to preserve sentence context, and strings are deduplicated - Translate — the subject and all unique strings are sent to OpenAI in a single request as a JSON array; OpenAI returns the translated strings and the detected source locale
- Skip if same locale — if the detected source language matches the target, the original content is returned unchanged
- Inject — translated strings are mapped back into their original positions in the HTML tree
- RTL — if the target locale is right-to-left,
dir="rtl"is injected on the root<html>element