diff --git a/config/packages/chill.yaml b/config/packages/chill.yaml index 6ed6b6984..e0beec4b4 100644 --- a/config/packages/chill.yaml +++ b/config/packages/chill.yaml @@ -1,5 +1,5 @@ chill_main: - available_languages: [ '%env(resolve:LOCALE)%', 'en' ] + available_languages: [ '%env(resolve:LOCALE)%', 'en', 'nl' ] available_countries: ['BE', 'FR'] notifications: from_email: '%env(resolve:NOTIFICATION_FROM_EMAIL)%' diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 15e247a27..b5539aa83 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -727,10 +727,6 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter public function setLocale(string $locale): self { - if (!in_array($locale, ['fr', 'nl'], true)) { - throw new \InvalidArgumentException('Locale must be either "fr" or "nl"'); - } - $this->locale = $locale; return $this; diff --git a/src/Bundle/ChillMainBundle/Form/Type/UserLocaleType.php b/src/Bundle/ChillMainBundle/Form/Type/UserLocaleType.php index d26278723..8e9c7fa62 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/UserLocaleType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/UserLocaleType.php @@ -13,17 +13,22 @@ namespace Chill\MainBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Intl\Languages; use Symfony\Component\OptionsResolver\OptionsResolver; class UserLocaleType extends AbstractType { + public function __construct(private readonly array $availableLanguages) {} + public function configureOptions(OptionsResolver $resolver): void { + $choices = []; + foreach ($this->availableLanguages as $languageCode) { + $choices[Languages::getName($languageCode)] = $languageCode; + } + $resolver->setDefaults([ - 'choices' => [ - 'user.locale.choice.french' => 'fr', - 'user.locale.choice.dutch' => 'nl', - ], + 'choices' => $choices, 'placeholder' => 'user.locale.placeholder', 'required' => true, 'label' => 'user.locale.label', diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index e917b37c9..ab7a49c68 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -12,6 +12,12 @@ services: tags: - { name: form.type, alias: translatable_string } + Chill\MainBundle\Form\Type\UserLocaleType: + arguments: + - "%chill_main.available_languages%" + tags: + - { name: form.type } + chill.main.form.type.select2choice: class: Chill\MainBundle\Form\Type\Select2ChoiceType tags: diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 5f75bc49c..8f5510d17 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -60,9 +60,6 @@ user: label: Langue de communication help: Langue utilisée pour les notifications par email et autres communications. placeholder: Choisissez une langue - choice: - french: Français - dutch: Nederlands user_group: inactive: Inactif