From 079d312ead6898ac11d4ca228b38633c5f113470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Poirier=20Th=C3=A9or=C3=AAt?= Date: Thu, 7 Dec 2023 15:23:48 -0500 Subject: [PATCH] [Mailer] default translations tokent for call to action template --- .../Mailer/UserNameFromEmailEmailWriter.php | 19 +++++++++++++++++++ packages/mailer/Email/CallToActionEmail.php | 4 ++++ .../Resources/translations/DrawEmail.en.yaml | 2 +- .../Resources/translations/DrawEmail.fr.yaml | 2 +- .../Email/Layout/call_to_action.html.twig | 19 ++++++++++--------- translations/DrawEmail.en.yaml | 1 + 6 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 app/src/Mailer/UserNameFromEmailEmailWriter.php diff --git a/app/src/Mailer/UserNameFromEmailEmailWriter.php b/app/src/Mailer/UserNameFromEmailEmailWriter.php new file mode 100644 index 000000000..671ba4a7f --- /dev/null +++ b/app/src/Mailer/UserNameFromEmailEmailWriter.php @@ -0,0 +1,19 @@ + -255]; + } + + public function compose(CallToActionEmail $email): void + { + $email->translationTokens['%user_name%'] = 'John Doe'; + } +} diff --git a/packages/mailer/Email/CallToActionEmail.php b/packages/mailer/Email/CallToActionEmail.php index 0862cb45f..16ef3a9a2 100644 --- a/packages/mailer/Email/CallToActionEmail.php +++ b/packages/mailer/Email/CallToActionEmail.php @@ -8,12 +8,16 @@ class CallToActionEmail extends TemplatedEmail { private ?string $callToActionLink = null; + public array $translationTokens = []; + public function getContext(): array { $context = parent::getContext(); $context['call_to_action_link'] = $this->callToActionLink; + $context['translation_tokens'] = $this->translationTokens; + return $context; } diff --git a/packages/mailer/Resources/translations/DrawEmail.en.yaml b/packages/mailer/Resources/translations/DrawEmail.en.yaml index e9380f036..34690333a 100644 --- a/packages/mailer/Resources/translations/DrawEmail.en.yaml +++ b/packages/mailer/Resources/translations/DrawEmail.en.yaml @@ -8,4 +8,4 @@ email: bottom_section: '' signature: '

Thanks!

' company_address: 'Company Inc, 3 Abbey Road, San Francisco CA 94102' - unsubscribe: '
Don''t like these emails? Unsubscribe.' + unsubscribe: '
Don''t like these emails? Unsubscribe.' diff --git a/packages/mailer/Resources/translations/DrawEmail.fr.yaml b/packages/mailer/Resources/translations/DrawEmail.fr.yaml index 73e0f4e74..9116f6ff2 100644 --- a/packages/mailer/Resources/translations/DrawEmail.fr.yaml +++ b/packages/mailer/Resources/translations/DrawEmail.fr.yaml @@ -8,4 +8,4 @@ email: bottom_section: '' signature: '

Merci !

' company_address: 'Company Inc, 3 Abbey Road, San Francisco CA 94102' - unsubscribe: '
Vous ne voulez pas recevoir ces courriels ? Se désabonner.' + unsubscribe: '
Vous ne voulez pas recevoir ces courriels ? Se désabonner.' diff --git a/packages/mailer/Resources/views/Email/Layout/call_to_action.html.twig b/packages/mailer/Resources/views/Email/Layout/call_to_action.html.twig index 6fbe3e4df..245b0f138 100644 --- a/packages/mailer/Resources/views/Email/Layout/call_to_action.html.twig +++ b/packages/mailer/Resources/views/Email/Layout/call_to_action.html.twig @@ -1,5 +1,6 @@ {% trans_default_domain 'DrawEmail' %} {% set draw_email_name = draw_email_name|default('default') %} +{% set translation_tokens = translation_tokens|default({}) %} {% set _tokens = { 'subject': ['email.' ~ draw_email_name ~ '.subject', 'email.default.subject'], 'preview': ['email.' ~ draw_email_name ~ '.preview', 'email.default.preview'], @@ -16,7 +17,7 @@ - {% block subject %}{{ _tokens.subject|trans|raw }}{% endblock subject %} + {% block subject %}{{ _tokens.subject|trans(translation_tokens)|raw }}{% endblock subject %} {% block style %}