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 set up the session_context field in your database and populate it using a VM Execution in the Workflow Builder to automatically detect the language.
1. Create the session_context Field in Your Database
The Locale field (type: Text) is automatically created by JUNE in email, commerce, and multichannel lists. You don't need to create it manually.
Instead, you need to create a field called session_context with the type Object. This field stores the session context from which we will later read the language.
Navigate to Data Platform > Databases in the left sidebar.
Select the database where your newsletter contacts are stored.
Click Add Field and choose the type Object.
Enter session_context as the field name and save the field.
Note: The session context is only populated when contacts are created via a JUNE form (e.g. embed form or pop-up). CSV imports and API-created contacts do not have this context – in that case the fallback is used (see step 2).
2. Set Up VM Execution in Your Workflow
In your automation workflow (e.g. Double Opt-In or registration workflow), add an Update Data service after the trigger:
Click Add Service in the Workflow Builder and select Update Data.
Select the Locale field.
Choose VM Execution as the 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, imported, or API-created 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.

