Common approach for email template localisations seems to be quite akward if else liquid syntax in the templates:
Is there some reason the custom email provider could not be used for localisations?’
You could have for example a passwordless otp template in Auth0 email connection:
{% raw %}
{{ otpHeader }}
{% endraw %}
{{ code }}
Then in the custom provider action you would render the event.html content again with the dictionary and using the event.locale for deducting the selected language.
Action pseudo code:
exports.onExecuteCustomEmailProvider = async (event, api) => {
const selectedLocale = deductLanguage(event.locale)
const templateParams = { otpHeader: dictionary[selectedLocale].otpHeader }
const emailContent = renderLiquid(event.html, templateParams)
// send the email with e.g. sendgrid api
}
Indeed, localization for email templated is quite limited, being available only through liquid syntax. It would be a great function to allow the custom email providers to handle the localization of emails or have an option inside the Auth0 dashboard to allow localization settings.
I would suggest to post on our Feedback page regarding a potential use case and implementation for this.
If you have any other questions, feel free to let me know!
In our project we ended up using the templates and liquid in that traditional way. Using the custom email provider in the way I described in this post felt a bit too hacky.
Though I think you could have a OTP email template:
{
"code": "{{ code }}"
}
And then in the onExecuteCustomEmailProvider action pseudo code example:
exports.onExecuteCustomEmailProvider = async (event, api) => {
const selectedLocale = deductLanguage(event.locale)
const code = JSON.parse(event.text).code
const template = getTemplate(event.notification.message_type)
const emailContent = renderTemplate(template, { code, selectedLocale })
// send the email with e.g. sendgrid api
}
The getTemplate and renderTemplate functionality would be defined in the action code but left out of this pseudo code example.
Note I did not check if that json syntax is allowed as email template…