mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-08 13:18:22 +00:00
Improve locale setting within user profile, using Languages symfony component
This commit is contained in:
@@ -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)%'
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user