Skip to content

Commit 8d500e6

Browse files
committed
Add translations
1 parent 60a681d commit 8d500e6

File tree

5 files changed

+73
-22
lines changed

5 files changed

+73
-22
lines changed

resources/translations/messages.en.xlf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,24 @@ Thank you.</target>
684684
<source>Footer of public pages</source>
685685
<target>__Footer of public pages</target>
686686
</trans-unit>
687+
<trans-unit id="vmzIZ25" resname="Please confirm your subscription">
688+
<source>Please confirm your subscription</source>
689+
<target>__Please confirm your subscription</target>
690+
</trans-unit>
691+
<trans-unit id="rT_b2Tm" resname="No user details changed">
692+
<source>No user details changed</source>
693+
<target>__No user details changed</target>
694+
</trans-unit>
695+
<trans-unit id="1R4L28q" resname="%field% = %new%&#10;*changed* from %old%">
696+
<source>%field% = %new%
697+
*changed* from %old%</source>
698+
<target>__%field% = %new%
699+
*changed* from %old%</target>
700+
</trans-unit>
701+
<trans-unit id="rns1KOG" resname="Subscribed to %list%">
702+
<source>Subscribed to %list%</source>
703+
<target>__Subscribed to %list%</target>
704+
</trans-unit>
687705
</body>
688706
</file>
689707
</xliff>

src/Domain/Subscription/Service/Manager/SubscriberHistoryManager.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@
1111
use PhpList\Core\Domain\Subscription\Model\Subscriber;
1212
use PhpList\Core\Domain\Subscription\Model\SubscriberHistory;
1313
use PhpList\Core\Domain\Subscription\Repository\SubscriberHistoryRepository;
14+
use Symfony\Contracts\Translation\TranslatorInterface;
1415

1516
class SubscriberHistoryManager
1617
{
1718
private SubscriberHistoryRepository $repository;
1819
private ClientIpResolver $clientIpResolver;
1920
private SystemInfoCollector $systemInfoCollector;
21+
private TranslatorInterface $translator;
2022

2123
public function __construct(
2224
SubscriberHistoryRepository $repository,
2325
ClientIpResolver $clientIpResolver,
2426
SystemInfoCollector $systemInfoCollector,
27+
TranslatorInterface $translator,
2528
) {
2629
$this->repository = $repository;
2730
$this->clientIpResolver = $clientIpResolver;
2831
$this->systemInfoCollector = $systemInfoCollector;
32+
$this->translator = $translator;
2933
}
3034

3135
public function getHistory(int $lastId, int $limit, SubscriberHistoryFilter $filter): array
@@ -59,20 +63,21 @@ public function addHistoryFromImport(
5963
}
6064

6165
$lines = [];
62-
6366
if (empty($updatedData) && empty($listLines)) {
64-
$lines[] = 'No user details changed';
67+
$lines[] = $this->translator->trans('No user details changed');
6568
} else {
6669
$skip = ['password', 'modified'];
6770
foreach ($updatedData as $field => [$old, $new]) {
6871
if (in_array($field, $skip, true)) {
6972
continue;
7073
}
71-
$lines[] = sprintf(
72-
"%s = %s\n*changed* from %s",
73-
$field,
74-
json_encode($new),
75-
json_encode($old)
74+
$lines[] = $this->translator->trans(
75+
"%field% = %new%\n*changed* from %old%",
76+
[
77+
'%field' => $field,
78+
'%new%' => json_encode($new),
79+
'%old%' => json_encode($old)
80+
],
7681
);
7782
}
7883
foreach ($listLines as $line) {
@@ -82,7 +87,7 @@ public function addHistoryFromImport(
8287

8388
$this->addHistory(
8489
subscriber: $subscriber,
85-
message: 'Import by ' . $admin->getLoginName(),
90+
message: 'Import by ' . $admin?->getLoginName(),
8691
details: $headerLine . implode(PHP_EOL, $lines) . PHP_EOL
8792
);
8893
}

src/Domain/Subscription/Service/SubscriberCsvImporter.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/**
2626
* Service for importing subscribers from a CSV file.
2727
* @SuppressWarnings("CouplingBetweenObjects")
28+
* @SuppressWarnings("ExcessiveParameterList")
2829
*/
2930
class SubscriberCsvImporter
3031
{
@@ -65,14 +66,14 @@ public function __construct(
6566

6667
/**
6768
* Import subscribers from a CSV file.
68-
*
69-
* @param UploadedFile $file The uploaded CSV file
70-
* @param SubscriberImportOptions $options
71-
* @param ?Administrator $admin
7269
* @return array Import statistics
70+
* @throws CouldNotReadUploadedFileException
7371
*/
74-
public function importFromCsv(UploadedFile $file, SubscriberImportOptions $options, ?Administrator $admin = null): array
75-
{
72+
public function importFromCsv(
73+
UploadedFile $file,
74+
SubscriberImportOptions $options,
75+
?Administrator $admin = null
76+
): array {
7677
$stats = [
7778
'created' => 0,
7879
'updated' => 0,
@@ -123,8 +124,12 @@ public function importFromCsv(UploadedFile $file, SubscriberImportOptions $optio
123124
* @param UploadedFile $file The uploaded CSV file
124125
* @return array Import statistics
125126
*/
126-
public function importAndUpdateFromCsv(UploadedFile $file, Administrator $admin, ?array $listIds = [], bool $dryRun = false): array
127-
{
127+
public function importAndUpdateFromCsv(
128+
UploadedFile $file,
129+
Administrator $admin,
130+
?array $listIds = [],
131+
bool $dryRun = false
132+
): array {
128133
return $this->importFromCsv(
129134
file: $file,
130135
options: new SubscriberImportOptions(updateExisting: true, listIds: $listIds, dryRun: $dryRun),
@@ -138,8 +143,12 @@ public function importAndUpdateFromCsv(UploadedFile $file, Administrator $admin,
138143
* @param UploadedFile $file The uploaded CSV file
139144
* @return array Import statistics
140145
*/
141-
public function importNewFromCsv(UploadedFile $file, Administrator $admin, ?array $listIds = [], bool $dryRun = false): array
142-
{
146+
public function importNewFromCsv(
147+
UploadedFile $file,
148+
Administrator $admin,
149+
?array $listIds = [],
150+
bool $dryRun = false
151+
): array {
143152
return $this->importFromCsv(
144153
file: $file,
145154
options: new SubscriberImportOptions(listIds: $listIds, dryRun: $dryRun),
@@ -161,9 +170,7 @@ private function processRow(
161170
}
162171

163172
$subscriber = $this->subscriberRepository->findOneByEmail($dto->email);
164-
if ($subscriber && !$options->updateExisting) {
165-
$stats['skipped']++;
166-
173+
if ($this->handleSkipCase($subscriber, $options, $stats)) {
167174
return;
168175
}
169176

@@ -184,7 +191,10 @@ private function processRow(
184191
$created = $this->subscriptionManager->addSubscriberToAList($subscriber, $listId);
185192
if ($created) {
186193
$addedNewSubscriberToList = true;
187-
$listLines[] = sprintf('Subscribed to %s', $created->getSubscriberList()->getName());
194+
$listLines[] = $this->translator->trans(
195+
'Subscribed to %list%',
196+
['%list%' => $created->getSubscriberList()->getName()]
197+
);
188198
}
189199
}
190200
}
@@ -217,6 +227,20 @@ private function handleInvalidEmail(
217227
return false;
218228
}
219229

230+
private function handleSkipCase(
231+
?Subscriber $existingSubscriber,
232+
SubscriberImportOptions $options,
233+
array &$stats
234+
): bool {
235+
if ($existingSubscriber && !$options->updateExisting) {
236+
$stats['skipped']++;
237+
238+
return true;
239+
}
240+
241+
return false;
242+
}
243+
220244
private function handleFlushAndEmail(
221245
Subscriber $subscriber,
222246
SubscriberImportOptions $options,

tests/Unit/Domain/Subscription/Service/Manager/SubscriberHistoryManagerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpList\Core\Domain\Subscription\Service\Manager\SubscriberHistoryManager;
1313
use PHPUnit\Framework\MockObject\MockObject;
1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Contracts\Translation\TranslatorInterface;
1516

1617
class SubscriberHistoryManagerTest extends TestCase
1718
{
@@ -25,6 +26,7 @@ protected function setUp(): void
2526
repository: $this->subscriberHistoryRepository,
2627
clientIpResolver: $this->createMock(ClientIpResolver::class),
2728
systemInfoCollector: $this->createMock(SystemInfoCollector::class),
29+
translator: $this->createMock(TranslatorInterface::class),
2830
);
2931
}
3032

tests/Unit/Domain/Subscription/Service/SubscriberCsvImporterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpList\Core\Domain\Subscription\Repository\SubscriberRepository;
1414
use PhpList\Core\Domain\Subscription\Service\CsvImporter;
1515
use PhpList\Core\Domain\Subscription\Service\Manager\SubscriberAttributeManager;
16+
use PhpList\Core\Domain\Subscription\Service\Manager\SubscriberHistoryManager;
1617
use PhpList\Core\Domain\Subscription\Service\Manager\SubscriberManager;
1718
use PhpList\Core\Domain\Subscription\Service\Manager\SubscriptionManager;
1819
use PhpList\Core\Domain\Subscription\Service\SubscriberCsvImporter;
@@ -51,6 +52,7 @@ protected function setUp(): void
5152
entityManager: $entityManager,
5253
translator: new Translator('en'),
5354
messageBus: $this->createMock(MessageBusInterface::class),
55+
subscriberHistoryManager: $this->createMock(SubscriberHistoryManager::class),
5456
);
5557
}
5658

0 commit comments

Comments
 (0)