Skip to main content

Multilingual Newsletters: Detect Language Automatically

Set up a Locale field to automatically detect your contacts' language and send multilingual newsletters.

Written by Anni Wild

Multilingual Newsletters: Detect Language Automatically

If you send newsletters in multiple languages (e.g. German and English), you can automatically detect the user's language from their session context after sign-up and save it in a database field. Your automations can then send the correct language version of your emails.

This article shows you how to create a Locale field in your database and populate it using a VM Execution in the Workflow Builder.


1. Create the Locale Field in Your Database

  1. Navigate to Data Platform > Databases in the left sidebar.

  2. Select the database where your newsletter contacts are stored.

  3. Click Add Field and choose the type Text (single-line).

  4. Enter Locale as the field name and save the field.


2. Set Up VM Execution in Your Workflow

In your workflow (e.g. Double Opt-In or registration workflow), add an Update Data service after the trigger:

  1. Click Add Service in the Workflow Builder and select Update Data.

  2. Select the Locale field.

  3. Choose VM Execution as execution type and insert the following code:

(function(data){
if (data.session_context && data.session_context.hasOwnProperty('client_lang')) {
if (['de', 'en'].indexOf(data.session_context.client_lang) >= 0) {
return data.session_context.client_lang;
}
}
return 'en';
})

Note: The fallback to 'en' ensures that users without a session context (e.g. manually created or imported contacts) always receive a valid language. You can extend the array ['de', 'en'] with additional languages, e.g. ['de', 'en', 'fr'].


3. Use Language in Emails

Once the Locale field is populated, you can use it in your email templates and automations:

  • Condition: Use a Condition with Code Execution to send different emails based on the Locale value.

  • Placeholder: Use the {{Locale}} placeholder in your emails to display the language dynamically.

  • Segmentation: Create segments based on the Locale field, e.g. "Locale is de" for all German-speaking contacts.

🔎 Learn how to build a DOI workflow with language detection in the Double Opt-In Automation article. For more on VM Executions, see here.

Did this answer your question?