Skip to content

Commit

Permalink
bug #6121 Fix an issue related to the translation of country names (j…
Browse files Browse the repository at this point in the history
…aviereguiluz)

This PR was merged into the 4.x branch.

Discussion
----------

Fix an issue related to the translation of country names

`@psihius` reported this problem to me. When using a `CountryField`, you get hundreds of "missing translation" errors. We already pass the country names translated to the form, so there's no need to try to translate them again.

Commits
-------

03150db Fix an issue related to the translation of country names
  • Loading branch information
javiereguiluz committed Jan 28, 2024
2 parents d6292e0 + 03150db commit b736249
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Field/Configurator/CountryConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
}

if (\in_array($context->getCrud()->getCurrentPage(), [Crud::PAGE_EDIT, Crud::PAGE_NEW], true)) {
// country names passed to the form are already translated, so don't translate them again in the template
$field->setFormTypeOptionIfNotSet('choice_translation_domain', false);
$field->setFormTypeOption('choices', $this->generateFormTypeChoices($countryCodeFormat, $field->getCustomOption(CountryField::OPTION_COUNTRY_CODES_TO_KEEP), $field->getCustomOption(CountryField::OPTION_COUNTRY_CODES_TO_REMOVE)));

// the value of this form option must be a string to properly propagate it as an HTML attribute value
Expand Down

0 comments on commit b736249

Please sign in to comment.