Question

In my parameters.yml I have this:

parameters:
    locale: en-gb

In my user entity I have this:

/**
 * @ORM\Column(name="Country", type="string", length=2)
 * @Assert\Country(message = "The country '{{ value }}' is not a valid country.")
 * @Assert\NotBlank()
 */
private $country;

When I use a form, the validation complains that: "The country 'US' is not a valid country."

So I had a hunt around in: /src/Symfony/Component/Validator/Constraints/CountryValidator

And came across:

$countries = Intl::getRegionBundle()->getCountryNames();

So I stuck that in my code to see what was in it. What was in it, was this:

array(1) { ["UM"]=> string(27) "U.S. Minor Outlying Islands" } 

Rather than the 258 countries it should have.

If I change my locale to en instead of en-gb, I get the 258 countries in the array.

So, my question is whether my parameters.yml should look like this?

parameters:
    locale: en, en-gb

Or some such? So that it takes everything from en and overrides what is needed with en-gb.

Or is this a bug? (It seems this was a bug in the version I was using. 2.3.1 and is now fixed in 2.3.5) - Thanks to Ritter for this information.

Was it helpful?

Solution

I believe this is a bug, as the same code works correctly in Symfony 2.1.

I have raised a bug report here:

https://github.com/symfony/symfony/issues/9180

Please feel free to add comments, or further information.

OTHER TIPS

I believe if you want to specify multiples you need to use a pipe (|)

So like this

locale: en|fr|de

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top