Why Use Locales?
Elemental’s locale system lets you create a single template that automatically adapts to your users’ preferred languages. Instead of maintaining separate templates for each language, define translations once and Courier handles the rest.- Single template, multiple languages: One template structure with translations for all supported locales
- Automatic selection: Courier uses the recipient’s locale from their profile or the
message.to.localefield - Fallback support: If a translation is missing, Courier uses the default content
- Consistent structure: Keep the same layout and logic across all languages
Supported Elements and Properties
Locales can be applied to any Elemental element that has localizable properties. The following properties support localization:content: Text content intext,action,quote, andhtmlelementstitle: Title inmetaelements (email subject lines, push notification titles)href: URLs inactionandimageelementssrc: Image source URLs inimageelementselements: Inline text content elements (string, link, img) intextelements, or nested elements inchannelandgroupelementstemplate: Template strings injsonnetelements
How Locales Work
When you specify alocale in the message.to field, Courier automatically replaces the default property values with locale-specific translations for each element that has a matching locale definition.
The locale interface follows this structure:
Text Node Locale Resolution
Text elements support two content formats:content (a plain or markdown string) and elements (a structured array of inline nodes like string, link, and img). The locale system handles all combinations:
If a locale translation is missing for a specific element, Courier falls back to the default property value. This ensures your notifications always render, even if some translations are incomplete.
Basic Example
Here’s a simple example showing how to localize a text element:"fr", the text "Hello" is replaced with "Bonjour". If the locale is "es", it becomes "Hola". For any other locale (or if no locale is specified), the default "Hello" is used.
Localizing Multiple Elements
You can localize multiple elements in a single template. Here’s a comprehensive example showing localization for different element types:- Meta element: Localizing the email subject line (
titleproperty) - Text element: Localizing body content with Handlebars variables
- Action element: Localizing both button text (
content) and URL (href)
Localizing Text Elements with Structured Elements
When your text node uses theelements array (with inline string, link, and img nodes), you can provide locale translations as elements arrays too. This preserves rich formatting like bold, italic, and inline links across languages.
Mixed Locale Formats
You can mixcontent and elements across different locales within the same text node. This is useful when some translations need rich formatting while others can use simple strings:
content string (which Courier wraps into a single text element at render time), while the Spanish locale preserves the structured elements with an inline link.
When Both content and elements Are Present
If a locale entry includes both content and elements, only elements is used — content is ignored. We recommend choosing one format per locale entry to keep your templates clear. See the resolution table for all combinations.
Locale Sources
Courier determines the recipient’s locale from the following sources, in order of precedence:message.to.locale: Explicitly set in thetoobject of the send request (highest priority)profile.locale: Set in the top-levelprofileobject of the send request- User profile locale: Stored in the user’s profile via the Profiles API
- Default fallback: If no locale is found, the default content is used
When
message.to.locale is provided, it takes precedence over all other locale sources. The locale from message.to is merged into the profile object during processing, so it will override any locale stored in the user’s profile or passed in the top-level profile object.Best Practices
Use Consistent Locale Codes
Use standard locale codes (e.g.,en-US, es-ES, fr-FR) or simple language codes (e.g., en, es, fr) consistently across your templates. Courier supports any locale string format, but consistency makes maintenance easier.
Provide Default Content
Always provide default content for each element. This ensures your notifications render correctly even if:- A user’s locale isn’t supported
- A translation is missing
- The locale field is omitted
Localize URLs When Needed
For action buttons and images, consider localizing thehref and src properties to point to localized versions of your website or app:
Combine with Channel-Specific Customization
You can combine locales with channel-specific customization to create fully localized, channel-optimized notifications:Test All Locales
Before deploying, test your templates with all supported locales to ensure:- All translations are present
- Handlebars variables work correctly in all languages
- URLs and links are properly localized
- Text fits within UI constraints (button sizes, email widths, etc.)