Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
<source>confirm.registration.complete</source>
<target>Ihr Newsletter-Abo ist nun aktiv.</target>
</trans-unit>
<trans-unit id="start.registration.label.email.address" resname="start.registration.label.email.address">
<source>start.registration.label.email.address</source>
<target>E-Mail-Adresse</target>
</trans-unit>
<trans-unit id="registration.label.categories" resname="registration.label.categories">
<source>registration.label.categories</source>
<target>Kategorien</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
<source>confirm.registration.complete</source>
<target>Your newsletter registration is now active.</target>
</trans-unit>
<trans-unit id="start.registration.label.email.address" resname="start.registration.label.email.address">
<source>start.registration.label.email.address</source>
<target>Email address</target>
</trans-unit>
<trans-unit id="registration.label.categories" resname="registration.label.categories">
<source>registration.label.categories</source>
<target>Categories</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 2 additions & 1 deletion src/EditRegistration/TypeHasCategoriesElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ protected function addCategoriesElementToForm(FormBuilderInterface $builder, arr
self::ELEMENT_CATEGORIES,
ChoiceType::class,
[
'label' => 'Categories',
'label' => 'registration.label.categories',
'translation_domain' => 'webfactory-newsletter-registration',
'multiple' => true,
'expanded' => true,
'choices' => $choices,
Expand Down
3 changes: 2 additions & 1 deletion src/StartRegistration/EmailAddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function configureOptions(OptionsResolver $resolver): void
'empty_data' => null,
'required' => true,
'compound' => false,
'label' => 'Email address',
'label' => 'start.registration.label.email.address',
'translation_domain' => 'webfactory-newsletter-registration',
'constraints' => [
new NotBlank(),
new Email(),
Expand Down
32 changes: 32 additions & 0 deletions tests/Resources/TranslationsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Webfactory\NewsletterRegistrationBundle\Tests\Resources;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Loader\XliffFileLoader;

class TranslationsTest extends TestCase
{
protected const DOMAIN = 'webfactory-newsletter-registration';

public static function provideLabelKeysAndLocales(): iterable
{
foreach (['de', 'en'] as $locale) {
yield [$locale, 'registration.label.categories'];
yield [$locale, 'start.registration.label.email.address'];
}
}

#[Test]
#[DataProvider('provideLabelKeysAndLocales')]
public function form_labels_are_translated(string $locale, string $key): void
{
$file = __DIR__.'/../../src/Resources/translations/'.self::DOMAIN.'+intl-icu.'.$locale.'.xlf';
$catalogue = (new XliffFileLoader())->load($file, $locale, self::DOMAIN);

$this->assertTrue($catalogue->has($key, self::DOMAIN), "Missing translation for '$key' in locale '$locale'.");
$this->assertNotEquals($key, $catalogue->get($key, self::DOMAIN));
}
}
9 changes: 9 additions & 0 deletions tests/StartRegistration/EmailAddressTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ public function provides_EmailAddress_if_submitted_with_valid_data()
$this->assertEquals('webfactory@example.com', $emailAddress->getEmailAddress());
}

#[Test]
public function has_translatable_label()
{
$view = $this->form->createView();

$this->assertEquals('start.registration.label.email.address', $view['emailAddress']->vars['label']);
$this->assertEquals('webfactory-newsletter-registration', $view['emailAddress']->vars['translation_domain']);
}

protected function getExtensions(): array
{
return [
Expand Down
11 changes: 11 additions & 0 deletions tests/StartRegistration/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ public function view_contains_category_choice_element_if_there_is_more_than_one_
$this->assertEquals($this->category2->getName(), $categoriesVars['choices'][1]->label);
}

#[Test]
public function category_choice_element_has_translatable_label(): void
{
$this->setUpTwoCategories();

$formView = $this->factory->create(StartRegistrationType::class)->createView();
$categoriesVars = $formView->vars['form']->children[StartRegistrationType::ELEMENT_CATEGORIES]->vars;
$this->assertEquals('registration.label.categories', $categoriesVars['label']);
$this->assertEquals('webfactory-newsletter-registration', $categoriesVars['translation_domain']);
}

#[Test]
public function does_not_validate_without_honeypot()
{
Expand Down
Loading