Auth0 Home Blog Docs

How to detect language in the Email Template, such as for "Change Password"?

email-template

#1

My site is using Auth0’s Lock UI to handle Logins and Password Reset Requests.

At the Lock UI, it is multilingual, with the JavaScript “options.language” being either “en” or “fr”.

In the Auth0 Admin Panel’s “Emails” -> “Templates” -> “Change Password”, is there a variable/macro that represents the language from the Lock UI that had triggered that Email Template?

What I want to do is something like this in the Email Template:

{% if lang == ‘fr’ %}Bonjour{% else %}Hello{% endif %}

So if the user was using Lock in French, then the Password Reset Email will be in French, and if they then changed it to English, then triggering the Password Reset Email would send off an English email instead.


#2

The user.user_metadata contain the user locale.

{% if user.user_metadata.locale == 'fr' %}
  Bienvenue au ...., {{ user.email }}
{% elsif user.user_metadata.locale == 'it' %}
  Benvenuti nel ..., {{ user.email }}
{% elsif user.user_metadata.locale == 'es' %}
  Bienvenido a ..., {{ user.email }}
{% elsif user.user_metadata.locale == 'pl' %}
  Witaj w ... {{ user.email }}
{% else %}
  Welcome to ..., {{ user.email }}
{% endif %}

#3

Thanks for the reply, but I do not have the locale stored in the user metadata.

I want to obtain the locale that was set in “Lock” in the JavaScript.