Skip to content

Commit 5627a03

Browse files
committed
Translate SubscriberConfirmationMessageHandler texts
1 parent 08d393e commit 5627a03

File tree

3 files changed

+74
-11
lines changed

3 files changed

+74
-11
lines changed

resources/translations/messages.en.xlf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,43 @@
7878
</target>
7979
</trans-unit>
8080

81+
<trans-unit id="identity.subscription_confirmation">
82+
<source>Please confirm your subscription</source>
83+
<target>Please confirm your subscription</target>
84+
</trans-unit>
85+
86+
<trans-unit id="identity.subscription_confirmation.text">
87+
<source>Thank you for subscribing!
88+
89+
Please confirm your subscription by clicking the link below:
90+
91+
%confirmationLink%
92+
93+
If you did not request this subscription, please ignore this email.
94+
</source>
95+
<target>Thank you for subscribing!
96+
97+
Please confirm your subscription by clicking the link below:
98+
99+
%confirmationLink%
100+
101+
If you did not request this subscription, please ignore this email.
102+
</target>
103+
</trans-unit>
104+
105+
<trans-unit id="identity.subscription_confirmation.html">
106+
<source><![CDATA[<p>Thank you for subscribing!</p>
107+
<p>Please confirm your subscription by clicking the link below:</p>
108+
<p><a href="%confirmationLink%">Confirm Subscription</a></p>
109+
<p>If you did not request this subscription, please ignore this email.</p>]]>
110+
</source>
111+
<target><![CDATA[<p>Thank you for subscribing!</p>
112+
<p>Please confirm your subscription by clicking the link below:</p>
113+
<p><a href="%confirmationLink%">Confirm Subscription</a></p>
114+
<p>If you did not request this subscription, please ignore this email.</p>]]>
115+
</target>
116+
</trans-unit>
117+
81118
<!-- Messaging -->
82119
<trans-unit id="messaging.imap_not_available">
83120
<source>PHP IMAP extension not available. Falling back to Webklex IMAP.</source>

src/Domain/Messaging/MessageHandler/SubscriberConfirmationMessageHandler.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpList\Core\Domain\Messaging\Service\EmailService;
99
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
1010
use Symfony\Component\Mime\Email;
11+
use Symfony\Contracts\Translation\TranslatorInterface;
1112

1213
/**
1314
* Handler for processing asynchronous subscriber confirmation email messages
@@ -16,11 +17,13 @@
1617
class SubscriberConfirmationMessageHandler
1718
{
1819
private EmailService $emailService;
20+
private TranslatorInterface $translator;
1921
private string $confirmationUrl;
2022

21-
public function __construct(EmailService $emailService, string $confirmationUrl)
23+
public function __construct(EmailService $emailService, TranslatorInterface $translator, string $confirmationUrl)
2224
{
2325
$this->emailService = $emailService;
26+
$this->translator = $translator;
2427
$this->confirmationUrl = $confirmationUrl;
2528
}
2629

@@ -31,18 +34,36 @@ public function __invoke(SubscriberConfirmationMessage $message): void
3134
{
3235
$confirmationLink = $this->generateConfirmationLink($message->getUniqueId());
3336

34-
$subject = 'Please confirm your subscription';
35-
$textContent = "Thank you for subscribing!\n\n"
36-
. "Please confirm your subscription by clicking the link below:\n"
37-
. $confirmationLink . "\n\n"
38-
. 'If you did not request this subscription, please ignore this email.';
37+
$subject = $this->translator->trans('Please confirm your subscription');
38+
39+
$textContent = $this->translator->trans(
40+
<<<TXT
41+
Thank you for subscribing!
42+
43+
Please confirm your subscription by clicking the link below:
44+
45+
%confirmationLink%
46+
47+
If you did not request this subscription, please ignore this email.
48+
TXT,
49+
[
50+
'%confirmationLink%' => $confirmationLink
51+
]
52+
);
3953

4054
$htmlContent = '';
4155
if ($message->hasHtmlEmail()) {
42-
$htmlContent = '<p>Thank you for subscribing!</p>'
43-
. '<p>Please confirm your subscription by clicking the link below:</p>'
44-
. '<p><a href="' . $confirmationLink . '">Confirm Subscription</a></p>'
45-
. '<p>If you did not request this subscription, please ignore this email.</p>';
56+
$htmlContent = $this->translator->trans(
57+
<<<HTML
58+
<p>Thank you for subscribing!</p>
59+
<p>Please confirm your subscription by clicking the link below:</p>
60+
<p><a href="%confirmationLink%">Confirm Subscription</a></p>
61+
<p>If you did not request this subscription, please ignore this email.</p>
62+
HTML,
63+
[
64+
'%confirmationLink%' => $confirmationLink,
65+
]
66+
);
4667
}
4768

4869
$email = (new Email())

tests/Unit/Domain/Messaging/MessageHandler/SubscriberConfirmationMessageHandlerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPUnit\Framework\MockObject\MockObject;
1111
use PHPUnit\Framework\TestCase;
1212
use Symfony\Component\Mime\Email;
13+
use Symfony\Component\Translation\Translator;
1314

1415
class SubscriberConfirmationMessageHandlerTest extends TestCase
1516
{
@@ -20,7 +21,11 @@ class SubscriberConfirmationMessageHandlerTest extends TestCase
2021
protected function setUp(): void
2122
{
2223
$this->emailService = $this->createMock(EmailService::class);
23-
$this->handler = new SubscriberConfirmationMessageHandler($this->emailService, $this->confirmationUrl);
24+
$this->handler = new SubscriberConfirmationMessageHandler(
25+
emailService: $this->emailService,
26+
translator: new Translator('en'),
27+
confirmationUrl: $this->confirmationUrl
28+
);
2429
}
2530

2631
public function testInvokeWithTextEmail(): void

0 commit comments

Comments
 (0)