See all tutorials

Tutorials » How to localize email templates

Using Webpagebytes CMS, email templates are localized in the same way as a web page (localization in a web application) or a PDF generated document (localization of a PDF resource).

In order to localize an email template take the following tasks:

Extract the static texts into site messages

Step 1

In Webpagebytes CMS administration interface navigate to the site page that contains the email template content, extract the static strings and create site messages.

The static strings will be replaced with references to site messages by using the wpbMessages model key.

...
<p> Hi ${userName} </p>
<p> Your account was created with success. </p>
...
will become
...
<p> ${wpbMessages["email.hi"]} ${userName} </p>
<p> ${wpbMessages["email.account.success"]} </p>
...

As can be seen, the static strings 'Hi' and 'Your account was created with success.' were replaced with ${wpbMessages["email.hi"]} and ${wpbMessages["email.account.success"]}.

Add support for new languages

Step 2

In Webpagebytes CMS administration web interface navigate to Site Settings - Locale Settings and select the new project languages.

Translate the static strings

Step 3

In Webpagebytes CMS administration web interface navigate to Messages section and add translations for the new language(s).

Test the localized emails

Step 4

The project language detected by the CMS engine at runtime based on the current request url will be used to generate the email content. In other words if the user was browsing a French web page then the email content will contain French strings.
Localized email generated with Webpagebytes CMS

Fork me on GitHub