How to add translation with parameters in Angular template

When using angular core's translation mechanism, the translate pipe is our friend in the template. But what if we have dynamic parameters? In my case, I had to get the user's email address in a translation.

Solution

You can add arguments to the translate pipe!

{{ 'email_notify_text'| translate : { email: currentUser.email } }}"

And in my assets/i18n/en.json

  "email_notify_text": "Get notified on {{email}} when there is an update"

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!