Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jekuer committed Jan 12, 2025
1 parent 731d812 commit 21fe31a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export default defineHook(({ filter }, { services, getSchema, env }) => {

filter('email.send', async (input: any) => {

if (['password-reset', 'user-invitation', 'user-registration'].includes(input.template.name)) {
const templateName = input.template.name;

if (['password-reset', 'user-invitation', 'user-registration'].includes(templateName)) {

// take IP from the server this script is running on
const systemIp = ip.address();

// pull in any subject translation form the environment variable I18N_EMAIL_SUBJECTS (scheme: {"de": {"password-reset": "Passwort zurücksetzen", ...}, ...})
// TODO: Could also become a setting somewhere in the Directus app as an alternative to the environment variable
const i18nEmailSubjects = JSON.parse(env.I18N_EMAIL_SUBJECTS);
const i18nEmailSubjects = JSON.parse(env.I18N_EMAIL_SUBJECTS) || {};

// preparing the accountability object to be able searching directus users with admin rights
// this includes a lot of empty props, which is necessary to match the type of the accountability object
Expand All @@ -40,10 +42,10 @@ export default defineHook(({ filter }, { services, getSchema, env }) => {
const lang = response[0].language?.split('-')[0] ? response[0].language.split('-')[0] : defaultLang;

// override the subject with the translation from the environment variable (if available)
input.subject = i18nEmailSubjects[lang][input.template.name] || input.subject;
input.subject = i18nEmailSubjects[lang] && i18nEmailSubjects[lang][templateName] ? i18nEmailSubjects[lang][templateName] : input.subject;
// override template for non-default languages
if (lang !== defaultLang) {
input.template.name = input.template.name + '-' + lang;
input.template.name = templateName + '-' + lang;
}

}
Expand Down

0 comments on commit 21fe31a

Please sign in to comment.