Skip to content

Commit fe66ee0

Browse files
committed
Translate
1 parent 8bf308a commit fe66ee0

File tree

9 files changed

+122
-27
lines changed

9 files changed

+122
-27
lines changed

resources/translations/messages.en.xlf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,56 @@
4545
<target>Another bounce processing is already running. Aborting.</target>
4646
</trans-unit>
4747

48+
<trans-unit id="messaging.queue_already_processing">
49+
<source>Queue is already being processed by another instance.</source>
50+
<target>Queue is already being processed by another instance.</target>
51+
</trans-unit>
52+
53+
<trans-unit id="messaging.maintenance_mode">
54+
<source>The system is in maintenance mode, stopping. Try again later.</source>
55+
<target>The system is in maintenance mode, stopping. Try again later.</target>
56+
</trans-unit>
57+
4858
<trans-unit id="messaging.bounce_processing_completed">
4959
<source>Bounce processing completed.</source>
5060
<target>Bounce processing completed.</target>
5161
</trans-unit>
5262

63+
<trans-unit id="messaging.recipient_not_provided">
64+
<source>Recipient email address not provided</source>
65+
<target>Recipient email address not provided</target>
66+
</trans-unit>
67+
68+
<trans-unit id="messaging.invalid_email">
69+
<source>Invalid email address: %email%</source>
70+
<target>Invalid email address: %email%</target>
71+
</trans-unit>
72+
73+
<trans-unit id="messaging.sending_test_email_sync">
74+
<source>Sending test email synchronously to %email%</source>
75+
<target>Sending test email synchronously to %email%</target>
76+
</trans-unit>
77+
78+
<trans-unit id="messaging.queuing_test_email">
79+
<source>Queuing test email for %email%</source>
80+
<target>Queuing test email for %email%</target>
81+
</trans-unit>
82+
83+
<trans-unit id="messaging.test_email_sent_success">
84+
<source>Test email sent successfully!</source>
85+
<target>Test email sent successfully!</target>
86+
</trans-unit>
87+
88+
<trans-unit id="messaging.test_email_queued_success">
89+
<source>Test email queued successfully! It will be sent asynchronously.</source>
90+
<target>Test email queued successfully! It will be sent asynchronously.</target>
91+
</trans-unit>
92+
93+
<trans-unit id="messaging.failed_to_send_test_email">
94+
<source>Failed to send test email: %error%</source>
95+
<target>Failed to send test email: %error%</target>
96+
</trans-unit>
97+
5398
<!-- Subscription -->
5499
<trans-unit id="subscription.list_not_found">
55100
<source>Subscriber list not found.</source>

src/Domain/Common/Repository/CursorPaginationTrait.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use BadMethodCallException;
88
use PhpList\Core\Domain\Common\Model\Filter\FilterRequestInterface;
99
use PhpList\Core\Domain\Common\Model\Interfaces\DomainModel;
10-
use RuntimeException;
1110

1211
trait CursorPaginationTrait
1312
{
@@ -31,8 +30,8 @@ public function getAfterId(int $lastId, int $limit): array
3130
* Get filtered + paginated messages for a given owner and status.
3231
*
3332
* @return DomainModel[]
34-
* @throws RuntimeException
35-
*/
33+
* @throws BadMethodCallException
34+
* */
3635
public function getFilteredAfterId(int $lastId, int $limit, ?FilterRequestInterface $filter = null): array
3736
{
3837
if ($filter === null) {

src/Domain/Messaging/Command/ProcessQueueCommand.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
1717
use Symfony\Component\Lock\LockFactory;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1819
use Throwable;
1920

2021
#[AsCommand(
@@ -28,20 +29,23 @@ class ProcessQueueCommand extends Command
2829
private MessageProcessingPreparator $messagePreparator;
2930
private CampaignProcessor $campaignProcessor;
3031
private ConfigManager $configManager;
32+
private TranslatorInterface $translator;
3133

3234
public function __construct(
3335
MessageRepository $messageRepository,
3436
LockFactory $lockFactory,
3537
MessageProcessingPreparator $messagePreparator,
3638
CampaignProcessor $campaignProcessor,
37-
ConfigManager $configManager
39+
ConfigManager $configManager,
40+
TranslatorInterface $translator
3841
) {
3942
parent::__construct();
4043
$this->messageRepository = $messageRepository;
4144
$this->lockFactory = $lockFactory;
4245
$this->messagePreparator = $messagePreparator;
4346
$this->campaignProcessor = $campaignProcessor;
4447
$this->configManager = $configManager;
48+
$this->translator = $translator;
4549
}
4650

4751
/**
@@ -51,13 +55,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5155
{
5256
$lock = $this->lockFactory->createLock('queue_processor');
5357
if (!$lock->acquire()) {
54-
$output->writeln('Queue is already being processed by another instance.');
58+
$output->writeln($this->translator->trans('Queue is already being processed by another instance.'));
5559

5660
return Command::FAILURE;
5761
}
5862

5963
if ($this->configManager->inMaintenanceMode()) {
60-
$output->writeln('The system is in maintenance mode, stopping. Try again later.');
64+
$output->writeln(
65+
$this->translator->trans('The system is in maintenance mode, stopping. Try again later.')
66+
);
6167

6268
return Command::FAILURE;
6369
}

src/Domain/Messaging/Command/SendTestEmailCommand.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Output\OutputInterface;
1414
use Symfony\Component\Mime\Address;
15+
use Symfony\Contracts\Translation\TranslatorInterface;
1516
use Symfony\Component\Mime\Email;
1617

1718
#[AsCommand(
@@ -21,11 +22,13 @@
2122
class SendTestEmailCommand extends Command
2223
{
2324
private EmailService $emailService;
25+
private TranslatorInterface $translator;
2426

25-
public function __construct(EmailService $emailService)
27+
public function __construct(EmailService $emailService, TranslatorInterface $translator)
2628
{
2729
parent::__construct();
2830
$this->emailService = $emailService;
31+
$this->translator = $translator;
2932
}
3033

3134
protected function configure(): void
@@ -48,13 +51,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4851
{
4952
$recipient = $input->getArgument('recipient');
5053
if (!$recipient) {
51-
$output->writeln('Recipient email address not provided');
54+
$output->writeln($this->translator->trans('Recipient email address not provided'));
5255

5356
return Command::FAILURE;
5457
}
5558

5659
if (!filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
57-
$output->writeln('Invalid email address: ' . $recipient);
60+
$output->writeln($this->translator->trans('Invalid email address: %email%', ['%email%' => $recipient]));
5861

5962
return Command::FAILURE;
6063
}
@@ -63,9 +66,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6366
$syncMode = $input->getOption('sync');
6467

6568
if ($syncMode) {
66-
$output->writeln('Sending test email synchronously to ' . $recipient);
69+
$output->writeln($this->translator->trans(
70+
'Sending test email synchronously to %email%',
71+
['%email%' => $recipient]
72+
));
6773
} else {
68-
$output->writeln('Queuing test email for ' . $recipient);
74+
$output->writeln($this->translator->trans(
75+
'Queuing test email for %email%',
76+
['%email%' => $recipient]
77+
));
6978
}
7079

7180
$email = (new Email())
@@ -77,15 +86,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7786

7887
if ($syncMode) {
7988
$this->emailService->sendEmailSync($email);
80-
$output->writeln('Test email sent successfully!');
89+
$output->writeln($this->translator->trans('Test email sent successfully!'));
8190
} else {
8291
$this->emailService->sendEmail($email);
83-
$output->writeln('Test email queued successfully! It will be sent asynchronously.');
92+
$output->writeln($this->translator->trans(
93+
'Test email queued successfully! It will be sent asynchronously.'
94+
));
8495
}
8596

8697
return Command::SUCCESS;
8798
} catch (Exception $e) {
88-
$output->writeln('Failed to send test email: ' . $e->getMessage());
99+
$output->writeln($this->translator->trans(
100+
'Failed to send test email: %error%',
101+
['%error%' => $e->getMessage()]
102+
));
89103

90104
return Command::FAILURE;
91105
}

tests/Unit/Domain/Common/Repository/CursorPaginationTraitTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace PhpList\Core\Tests\Unit\Domain\Common\Repository;
66

7+
use BadMethodCallException;
78
use Doctrine\ORM\Query;
89
use Doctrine\ORM\QueryBuilder;
910
use PhpList\Core\Domain\Common\Model\Filter\FilterRequestInterface;
1011
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\TestCase;
12-
use RuntimeException;
1313

1414
final class CursorPaginationTraitTest extends TestCase
1515
{
@@ -59,8 +59,8 @@ public function testGetFilteredAfterIdWithFilterThrows(): void
5959
{
6060
$dummyFilter = $this->createMock(FilterRequestInterface::class);
6161

62-
$this->expectException(RuntimeException::class);
63-
$this->expectExceptionMessage('Filter method not implemented');
62+
$this->expectException(BadMethodCallException::class);
63+
$this->expectExceptionMessage('getFilteredAfterId method not implemented');
6464

6565
$this->repo->getFilteredAfterId(0, 10, $dummyFilter);
6666
}

tests/Unit/Domain/Identity/Service/AdminAttributeDefinitionManagerTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,24 @@
1212
use PhpList\Core\Domain\Subscription\Validator\AttributeTypeValidator;
1313
use PHPUnit\Framework\MockObject\MockObject;
1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Contracts\Translation\TranslatorInterface;
1516

1617
class AdminAttributeDefinitionManagerTest extends TestCase
1718
{
1819
private AdminAttributeDefinitionRepository&MockObject $repository;
1920
private AdminAttributeDefinitionManager $subject;
21+
private TranslatorInterface&MockObject $translator;
2022

2123
protected function setUp(): void
2224
{
2325
$this->repository = $this->createMock(AdminAttributeDefinitionRepository::class);
2426
$attributeTypeValidator = $this->createMock(AttributeTypeValidator::class);
25-
$this->subject = new AdminAttributeDefinitionManager($this->repository, $attributeTypeValidator);
27+
$this->translator = $this->createMock(TranslatorInterface::class);
28+
$this->subject = new AdminAttributeDefinitionManager(
29+
definitionRepository: $this->repository,
30+
attributeTypeValidator: $attributeTypeValidator,
31+
translator: $this->translator,
32+
);
2633
}
2734

2835
public function testCreateCreatesNewAttributeDefinition(): void
@@ -76,6 +83,11 @@ public function testCreateThrowsExceptionIfAttributeAlreadyExists(): void
7683
->with('test-attribute')
7784
->willReturn($existingAttribute);
7885

86+
$this->translator->expects($this->once())
87+
->method('trans')
88+
->with('Attribute definition already exists.')
89+
->willReturn('Attribute definition already exists.');
90+
7991
$this->expectException(AttributeDefinitionCreationException::class);
8092
$this->expectExceptionMessage('Attribute definition already exists');
8193

tests/Unit/Domain/Messaging/Command/ProcessBouncesCommandTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Psr\Log\LoggerInterface;
1717
use Symfony\Component\Console\Tester\CommandTester;
18+
use Symfony\Component\Translation\Translator;
19+
use Symfony\Contracts\Translation\TranslatorInterface;
1820

1921
class ProcessBouncesCommandTest extends TestCase
2022
{
@@ -26,6 +28,7 @@ class ProcessBouncesCommandTest extends TestCase
2628
private ConsecutiveBounceHandler&MockObject $consecutiveBounceHandler;
2729

2830
private CommandTester $commandTester;
31+
private TranslatorInterface|MockObject $translator;
2932

3033
protected function setUp(): void
3134
{
@@ -35,6 +38,7 @@ protected function setUp(): void
3538
$this->advancedRulesProcessor = $this->createMock(AdvancedBounceRulesProcessor::class);
3639
$this->unidentifiedReprocessor = $this->createMock(UnidentifiedBounceReprocessor::class);
3740
$this->consecutiveBounceHandler = $this->createMock(ConsecutiveBounceHandler::class);
41+
$this->translator = new Translator('en');
3842

3943
$command = new ProcessBouncesCommand(
4044
lockService: $this->lockService,
@@ -43,6 +47,7 @@ protected function setUp(): void
4347
advancedRulesProcessor: $this->advancedRulesProcessor,
4448
unidentifiedReprocessor: $this->unidentifiedReprocessor,
4549
consecutiveBounceHandler: $this->consecutiveBounceHandler,
50+
translator: $this->translator,
4651
);
4752

4853
$this->commandTester = new CommandTester($command);

tests/Unit/Domain/Messaging/Command/ProcessQueueCommandTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Tester\CommandTester;
1818
use Symfony\Component\Lock\LockFactory;
1919
use Symfony\Component\Lock\LockInterface;
20+
use Symfony\Component\Translation\Translator;
2021

2122
class ProcessQueueCommandTest extends TestCase
2223
{
@@ -25,6 +26,7 @@ class ProcessQueueCommandTest extends TestCase
2526
private CampaignProcessor&MockObject $campaignProcessor;
2627
private LockInterface&MockObject $lock;
2728
private CommandTester $commandTester;
29+
private Translator&MockObject $translator;
2830

2931
protected function setUp(): void
3032
{
@@ -33,17 +35,19 @@ protected function setUp(): void
3335
$this->messageProcessingPreparator = $this->createMock(MessageProcessingPreparator::class);
3436
$this->campaignProcessor = $this->createMock(CampaignProcessor::class);
3537
$this->lock = $this->createMock(LockInterface::class);
38+
$this->translator = $this->createMock(Translator::class);
3639

3740
$lockFactory->method('createLock')
3841
->with('queue_processor')
3942
->willReturn($this->lock);
4043

4144
$command = new ProcessQueueCommand(
42-
$this->messageRepository,
43-
$lockFactory,
44-
$this->messageProcessingPreparator,
45-
$this->campaignProcessor,
46-
$this->createMock(ConfigManager::class),
45+
messageRepository: $this->messageRepository,
46+
lockFactory: $lockFactory,
47+
messagePreparator: $this->messageProcessingPreparator,
48+
campaignProcessor: $this->campaignProcessor,
49+
configManager: $this->createMock(ConfigManager::class),
50+
translator: $this->translator,
4751
);
4852

4953
$application = new Application();
@@ -61,10 +65,15 @@ public function testExecuteWithLockAlreadyAcquired(): void
6165
$this->messageProcessingPreparator->expects($this->never())
6266
->method('ensureSubscribersHaveUuid');
6367

68+
$this->translator->expects($this->once())
69+
->method('trans')
70+
->with('Queue is already being processed by another instance.')
71+
->willReturn('Queue is already being processed by another instance.');
72+
6473
$this->commandTester->execute([]);
6574

6675
$output = $this->commandTester->getDisplay();
67-
$this->assertStringContainsString('Queue is already being processed by another instance', $output);
76+
$this->assertStringContainsString('Queue is already being processed by another instance.', $output);
6877
$this->assertEquals(1, $this->commandTester->getStatusCode());
6978
}
7079

0 commit comments

Comments
 (0)