Skip to content

Commit

Permalink
add German translation and use token factory again
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzmg committed May 23, 2024
1 parent 636e900 commit a78d7cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 6 additions & 2 deletions contao/languages/de/nc_tokens.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
<file datatype="php" source-language="en" target-language="de">
<body>
<trans-unit id="nc_tokens.admin_email">
<source>E-mail address of administrator of the current page (website root settings).</source>
<target>E-Mail-Adresse des Administrators der aktuellen Seite (Einstellungen der Rootseite).</target>
<source>E-mail address of the administrator of the current page (system config or website root settings).</source>
<target>E-Mail-Adresse des Administrators der aktuellen Seite (Systemeinstellungen oder Einstellungen der Rootseite).</target>
</trans-unit>
<trans-unit id="nc_tokens.admin_name">
<source>Friendly name for the e-mail address of the administrator of the current page (system config or website root settings).</source>
<target>Anzeigename für die E-Mail-Adresse des Administrators der aktuellen Seite (Systemeinstellungen oder Einstellungen der Rootseite).</target>
</trans-unit>
<trans-unit id="nc_tokens.form.form_*">
<source>All the form fields.</source>
Expand Down
8 changes: 4 additions & 4 deletions contao/languages/en/nc_tokens.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<xliff version="1.2">
<file datatype="php" source-language="en" target-language="en">
<body>
<trans-unit id="nc_tokens.admin_name">
<source>Friendly name for the e-mail address of the administrator of the current page (system config or website root settings).</source>
<target>Friendly name for the e-mail address of the administrator of the current page (system config or website root settings).</target>
</trans-unit>
<trans-unit id="nc_tokens.admin_email">
<source>E-mail address of the administrator of the current page (system config or website root settings).</source>
<target>E-mail address of the administrator of the current page (system config or website root settings).</target>
</trans-unit>
<trans-unit id="nc_tokens.admin_name">
<source>Friendly name for the e-mail address of the administrator of the current page (system config or website root settings).</source>
<target>Friendly name for the e-mail address of the administrator of the current page (system config or website root settings).</target>
</trans-unit>
<trans-unit id="nc_tokens.form.form_*">
<source>All the form fields.</source>
<target>All the form fields.</target>
Expand Down
15 changes: 10 additions & 5 deletions src/EventListener/AdminEmailTokenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Terminal42\NotificationCenterBundle\Parcel\Stamp\TokenCollectionStamp;
use Terminal42\NotificationCenterBundle\Token\Definition\EmailTokenDefinition;
use Terminal42\NotificationCenterBundle\Token\Definition\Factory\TokenDefinitionFactoryInterface;
use Terminal42\NotificationCenterBundle\Token\Token;
use Terminal42\NotificationCenterBundle\Token\Definition\TokenDefinitionInterface;

class AdminEmailTokenListener
{
Expand All @@ -30,8 +30,8 @@ public function __construct(
public function onGetTokenDefinitions(GetTokenDefinitionsForNotificationTypeEvent $event): void
{
$event
->addTokenDefinition($this->tokenDefinitionFactory->create(EmailTokenDefinition::class, 'admin_name', 'admin_name'))
->addTokenDefinition($this->tokenDefinitionFactory->create(EmailTokenDefinition::class, 'admin_email', 'admin_email'))
->addTokenDefinition($this->getTokenDefinition('admin_email'))
->addTokenDefinition($this->getTokenDefinition('admin_name'))
;
}

Expand All @@ -53,8 +53,8 @@ public function onCreateParcel(CreateParcelEvent $event): void
}

$event->getParcel()->getStamp(TokenCollectionStamp::class)->tokenCollection
->addToken(new Token('admin_name', $email[0], $email[0]))
->addToken(new Token('admin_email', $email[1], $email[1]))
->addToken($this->getTokenDefinition('admin_email')->createToken('admin_email', $email[1]))
->addToken($this->getTokenDefinition('admin_name')->createToken('admin_name', $email[0]))
;
}

Expand Down Expand Up @@ -82,6 +82,11 @@ private function getEmailFromConfig(): array|null
return $email ? $this->parseFriendlyEmail($email) : null;
}

private function getTokenDefinition(string $token): TokenDefinitionInterface
{
return $this->tokenDefinitionFactory->create(EmailTokenDefinition::class, $token, $token);
}

private function parseFriendlyEmail(string $email): array
{
return $this->contaoFramework->getAdapter(StringUtil::class)->splitFriendlyEmail($email);
Expand Down

0 comments on commit a78d7cb

Please sign in to comment.