Skip Navigation

Localizing Email Templates in Kentico

Suppose you visit a merchant’s website, browse their merchandise, and select products all while viewing the website in English.  You are able to easily find and understand information and add products to your cart.  However, during the checkout you realize you have forgotten your password and need to request a new one.  Unfortunately, you receive the password reset request email in French and unfortunately don’t speak French.  You may go to the effort of trying to discern the information you need from the email.  However, you are just as likely to abandon the site and find another merchant.  For customers, receiving emails in a language you don’t understand is frustrating.  For merchants, not being able to send emails to customers in their preferred language has the potential to negatively impact sales and revenue.

 If your Kentico website is multilingual, chances are you will want to communicate with site users in their preferred language across all communications avenues – including emails sent from the website.  While Kentico email templates do not offer the ability to specify a culture, you can effectively localize the email templates found within the Email Templates application in Kentico.  One possible solution would be to include translated text for multiple languages in the same template.  This approach, however, may not be preferable or even practical if the content is needed in numerous languages.  An alternative approach would be to use a custom EmailTemplateProvider combined with multiple versions of the email templates you wish to translate each of which contains content localized in a different language. 


“Multilingual” Templates

Even though you cannot assign a culture directly to an email template, you can enter localized content into the template itself.  So rather than creating a single template and providing localized versions of that template, you can create multiple templates in different languages.  For example:

Custom EmailTemplateProvider

In order for your website to select between the various “localized” versions of your email template, you will need to provide logic for determining which template to use in an override of the GetEmailTemplate method of an EmailTemplateProvider.  One possible approach would be to use a naming convention which includes the culture code, name or other identifying characteristic in the code name of the template. 



One code example of this approach using the culture code in the template code name is as follows. Using this code, if Kentico requests the template for “Membership.PasswordExpired”, it will check the culture. If the culture is “ca-fr”, it will look for a template with the code name “Membership.PasswordExpired-fr-ca”.  Using this solution, marketers can provide multiple versions of each email template to support all cultures.


using MyProject.CMSProviders;
using CMS;
using CMS.EmailEngine;
using System.Globalization;
[assembly: RegisterCustomProvider(typeof(CultureEmailTemplateProvider))]
namespace MyProject.CMSProviders
{
    public class CultureEmailTemplateProvider : EmailTemplateProvider
    {
        protected override EmailTemplateInfo GetEmailTemplateInternal(string templateName, string siteName)
        {
            var culture = CultureInfo.CurrentCulture?.Name?.ToLower() ?? "en-us";
            var cultureSpecificTemplateName = $"{templateName}-{culture}";
            var template = base.GetEmailTemplateInternal(cultureSpecificTemplateName, siteName);
            if (template != null)
            {
                return template;
            }
            return base.GetEmailTemplateInternal(templateName, siteName);
        }
    }
}

Conclusion

Delivering localized content in your email communications can be achieved with relative ease through the use of multiple email templates and a custom EmailTemplateProvider.  Providing localized content in emails will provide your users with a better experience on your site which in turn translates into increased sales.

Interested? Contact Us
Interested? Contact Us

Interested?

Send us a message using the form below or call us at 303.759.2100

Yay, you did it!!

Thanks for reaching out. We've received your message and will get back to you soon.

Oops. There's a problem.

This one’s on us, not on you. Please try submitting the form again, or if you prefer, you can email us at curious@bluemodus.com.