Email Template Language Customization

Overview

Auth0 generally allows using Liquid Syntax to customize email templates. One way to customize the language of the template is by using the request language header. This header will contain the languages a user sets up in their browser. However, when using this option, unless proper logic is used, the selection could render the template in the wrong language.

Applies To
  • Email Templates
Cause

The issue is caused by improper logic within the Liquid Syntax. 

Solution

The following Liquid Code sample provides strict logic which will render the template in the users language and will default to English in the event that the language is not supported.


{%- assign truncated_language = request_language | slice: 0, 2 -%} // the slice method is needed as otherwise the matching would fail

The language is: {{ truncated_language }}
</br>

{%- if truncated_language == 'de' -%}
  <p>Deutsch (German) language selected.</p>
{%- elsif truncated_language == 'fr' -%}
  <p>Français (French) language selected.</p>
{%- else -%}
  <p>Language not recognized or specified: {{ truncated_language }}</p>
{%- endif -%}

Header Example:

{
  "request_language": "de,fr,zh,zh,fr"
}

 

Output:

The language is: de
</br><p>Deutsch (German) language selected.</p>

Recommended content

No recommended content found...