EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Option "choice_translation_domain" is ignored

Open Ang3 opened this issue 2 years ago • 2 comments

Describe the bug The option choice_translation_domain is ignored on field of type ChoiceField.

To Reproduce

yield ChoiceField::new('myFieldName')
    ->setChoices(['abc' => 'abc'])
    ->setFormTypeOption('choice_translation_domain', false);

In the profiler toolbar, the value abc is missing translation message.

(OPTIONAL) Additional context

Versions:

  • EA: 4.1.2
  • Symfony: 6.0.7

EA processes to the translation instead of Symfony in the ChoiceConfigurator: https://github.com/EasyCorp/EasyAdminBundle/blob/63526b2cea854c79604e2da9f82abc8fcd018fde/src/Field/Configurator/ChoiceConfigurator.php#L72-L86

Line 79: you could add a condition on translation if the form type option choice_translation_domain is set to false like:

$choiceValue = false !== $field->getFormTypeOption('choice_translation_domain') 
  ? $this->translator->trans($selectedChoice, $translationParameters, $translationDomain) 
  : $selectedChoice;

Ang3 avatar Apr 23 '22 22:04 Ang3

In #5066 we're going to change everything about the internal handling of translations ... so let's wait until that it's merged to see if the error persists.

javiereguiluz avatar Apr 26 '22 18:04 javiereguiluz

Hi,

The pull request has been merged but there is still double translations.

Ang3 avatar Jul 07 '22 13:07 Ang3

With EA 4.6 it still ignores the domain, but only on the index and detail pages. There for some reason it always uses "messages" as domain.

Even when I set the choice values with t('key', [], 'my_domain') it ignores it and only takes the key with domain "messages".

Hm.. I suppose it's because the translation domain of the dashboard is used. But I would need domains per CRUD. So I can only solve this by translating beforehand.

But: If the developer uses t() it should just use this instead of modifying it.

mahono avatar Jun 10 '23 13:06 mahono