Multi-Language Templates

  1. Overview
  2. Is MLT for Your Application?
  3. End User Functionality
  4. Prerequisites
  5. Configuration Steps
  6. Lang Attribute
  7. Test the Configuration
  8. Export Translations
  9. Changing the Language
  10. Triggering the Translation Preview

Overview

Multi-language Templates (MLT) empower your end users to design customized experiences for their international audiences. Through the use of this feature, your end users will be able to select one default language, and three translations reflected in the top bar of their builder.

MLT does this by providing a translation infrastructure and supporting a translation service of your choosing. A few examples of how you can integrate MLT into your application include the following:

Note: The style of your templates stays the same across the language version while MLT is in use. The only change that will occur is the language of the text for the relevant components.

This Configuration Guide will help you get started with configuring the MLT feature. We recommend you start with the Prerequisites section to ensure you have everything you need for a successful configuration. 

If you are uncertain if your host application is a good candidate for this functionality, continue to the Is MLT for Your Application? section to learn more about this feature.

Is MLT for Your Application?

The Multi-language Templates (MLT) feature is an enhancement for companies working with end users who build emails that engage with international audiences.

MLT adds the following extended functionality to your host application:

  • Add a new language for the content inside Beefree SDK
  • Activate the language configuration in the Beefree SDK configuration file
  • Customize a list of languages the user can choose from
  • Allow changes to the default language
  • Enable preview for templates in different language versions

For more information on Multi-language Templates, visit our Multi-language Template Knowledge Base article.

End User Functionality

Multi-language Templates (MLT) offers the following in-app features for an application end user:

  • Switching the editor and template languages
  • Translate contents
  • Multi-language Template preview
  • Export HTML for multiple languages as single files
  • Alternative text descriptions
  • Changing an image path
    • This lets users switch email images for different translations. For instance, they can replace an image containing English text with the corresponding image containing Spanish text for the Spanish translation. 

For more detailed information on the MLT feature offering, visit our Multi-language Knowledge Base article.

Prerequisites

Before proceeding with the configuration, ensure you have:

  • Superpower or Enterprise plans
  • The multi-language support toggle set to on in the Beefree SDK Console
  • Application Client ID
  • Application Client secret

Configuration Steps

Take the following steps to configure Multi-language Templates (MLT) in your application.

Enable multi-language templates

  1. Log in to the Beefree SDK Console.
  2. Navigate to the multi-language template toggle.
  3. Toggle the feature to on, ensuring that the bright green on the toggle is showing.

Initialize multi-language templates

  1. Add the templateLanguage property to the config object. This property defines the default language for the template.
  2. Add the templateLanguages property to the config object. This property defines the list of language options for the template translations.
  3. Confirm you added both properties with the correct language options and save your changes. 

The following example shows the properties within the config object.




...
  templateLanguage: { value: 'en-US', label: 'English' },
  templateLanguages: [
    { value: 'it-IT', label: 'Italiano' },
    { value: 'he-IL', label: 'עִבְרִית' },
    { value: 'fr-FR', label: 'Français' },
  ],
...



Lang Attribute

The lang attribute on the content modules helps with hyphenation and screen readability.

Test the Configuration

Once you have initialized multi-language templates, you can confirm that the configuration was successful by following these instructions:

  1. Go to your builder.
  2. Navigate to the top bar.
  3. Confirm whether or not you see a language drop-down menu.

If you see a drop-down, the configuration was successful. If you do not see a drop-down, return to the Configuration Steps section and try them again.

Translation HTML

Multi-language Templates (MLT) offer the option to save and export translation HTML. This section outlines the steps you need to take to save or export a translation’s HTML.

Save HTML

To save the HTML output for a specific language take the following steps:

1. Use the bee.save method and provide the desired language as a parameter. In this example, we’ll save it for the Italian language (‘it-IT’).



bee.save({ language: 'it-IT' })

2. Set up an onSave event listener to handle the HTML saving process. This listener will be triggered when the HTML generation is complete. You can add it to the configuration object.




bee.configure({
  onSave: (pageJson, pageHtml, ampHtml, templateVersion, language) => {
    myApi.saveHtml(pageHtml, language);
  }
});



In the code above:

  • onSave is an event handler function that takes several parameters related to the generated HTML.
  • pageHtml contains the generated HTML.
  • language contains the requested language value, which was previously set in the bee.save method.

If you want to use the default main language for generating HTML when the bee.save method is called without parameters, you don’t need to specify a language in the bee.save method. The default language will be used automatically.

Export Translations

Take the steps outlined in this section to export the translation HTML.

  1. Define an array of languages that you want to export translations for. Each language should be represented as a string.

The following example shows an array of multiple export languages.




const languages = ['en-US', 'he-IL', 'it-IT'];


      2. Create a function, let’s call it exportAllTranslations as an example, which will iterate over the array of languages and call the bee.save method for each language.

View the following example function.




function exportAllTranslations() {
  languages.forEach(language => bee.save({ language }));
}



    3. Implement the onSave callbacks for each language. These callbacks will be triggered when the bee.save method completes for each language. Make sure to handle the specific language-related data within each callback.




// onSave callback for en-US
1. onSave: (
  pageJson, pageHtml, ampHtml, templateVersion, language // en-US
) => {
  // Handle the export for en-US here
  // You can access pageHtml, ampHtml, and other data
  // related to the en-US language export
}

// onSave callback for he-IL
2. onSave: (
  pageJson, pageHtml, ampHtml, templateVersion, language // he-IL
) => {
  // Handle the export for he-IL here
  // You can access pageHtml, ampHtml, and other data
  // related to the he-IL language export
}

// onSave callback for it-IT
3. onSave: (
  pageJson, pageHtml, ampHtml, templateVersion, language // it-IT
) => {
  // Handle the export for it-IT here
  // You can access pageHtml, ampHtml, and other data
  // related to the it-IT language export
}

// Repeat the above pattern for each language in the array



Changing the Language

Follow the steps outlined in this section to create a specified functionality that allows the end user to change their template language when a custom top bar is enabled.

  1. Ensure you have a custom top bar.

      2. Create a function to handle the language change. You can use the instance method bee.switchTemplateLanguage for this purpose.




bee.switchTemplateLanguage({ language: 'es-ES' })


    3. Verify if the specified language exists in the available languages. If it does, the language switch will happen automatically.

   Note: If the specified language does not exist among the available languages, an event will be fired to the onError callback.

   4. Once the language is successfully changed, a callback named onTemplateLanguageChange will be triggered. You need to define this callback function to respond to the language change.

 




onTemplateLanguageChange: (lang) => {
  console.log(lang) // Example output: { label: 'Spanish', value: 'es-ES', isMain: false }
}


The onTemplateLanguageChange callback will receive an object (lang) containing information about the language the user switched to. This object will have three properties:

  • label: The label or name of the language.
  • value: The value representing the language (e.g., ‘es-ES’ for Spanish).
  • isMain: A boolean property indicating whether the selected language is the default one, as defined with templateLanguage in the configuration object.

5. Test the language switching functionality by calling bee.switchTemplateLanguage with different language values, and make sure that the onTemplateLanguageChange callback responds correctly.

Triggering the Translation Preview

If you have a custom Preview, you can handle switching languages on the Preview.

To open the Preview, you can call either of two methods: bee.togglePreview or bee.switchPreview.

The methods perform the following tasks:

  • togglePreview: a toggle that opens and closes the Preview.
  • switchPreview: accepts a parameter to specify the language and get the HTML preview. It also opens the Preview if it’s closed.

The following code shows an example of the methods applied for the default language.




// Open the preview in the default language
bee.togglePreview() or bee.switchPreview()

// Switch to Italian
bee.switchPreview({ language: 'it-IT' })

// Close the preview
bee.togglePreview()


The following code shows an example of the methods applied for a preview in French.




// Open the preview in French
bee.switchPreview({ language: 'fr-FR' })

// Switch to Russian
bee.switchPreview({ language: 'ru-RU' })

// Close the preview
bee.togglePreview()


Note: The language parameter is optional in switchPreview. Calling it without parameters will open the Preview with the default language selected. If the Preview is open, nothing will happen. The same behavior is applied when the language passed is not valid or doesn’t exist.