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: 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:
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)
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.)
Related Approaches
Elemental locales are defined directly in your template JSON, making them ideal for templates where translations are known at template creation time. However, Courier offers other internationalization approaches that may better suit your needs:Related Documentation
Elements Reference
Complete reference for all Elemental element types and their properties, including locale support.
Localization
For Business customers: API-based translation workflow with webhooks, programmatic locale management, and translation service integration.
Control Flow
Combine locales with channel-specific customization and conditional logic.
Profiles API
Manage user profiles and set default locales for automatic localization.