Using Translations with @novu/framework
Learn how to use translations with @novu/framework based workflows
Novu Framework workflows are code-first: workflow definitions and content are expressed in code rather than in the dashboard. Internationalization (i18n) is implemented in the application layer—translations are defined there and resolved at runtime—so that workflow step content (e.g. subject and body fields) can be locale-aware.
This guide implements a locale-aware email notification workflow using i18next for translation resolution and React Email for the message template, with a Twitch welcome email as the reference implementation.
Import the createInstance and InitOptions from the i18next library and add translation keys for all supported locales.
- Create a new file called
react-email-template.tsxand add the following code using components from the@react-email/componentslibrary. - Add the
renderEmailfunction to render the email template.
Here, we are using @react-email/components to build the email template. You can use any other library or bare HTML to build the email template.
- Create the workflow definition by importing the
workflowfunction from the@novu/frameworklibrary. - Import the
renderEmailfunction from thereact-email-template.tsxfile. This is the email template that will be used to send the notification. - Import the
i18nfrom thetranslations.tsfile. - Import the
zodlibrary to validate the workflow payload.
- Sync the workflow to the Novu cloud.
- Test the workflow by triggering it to subscribers with different locales.