Skip to content

[Validator] Fix the locale validator so it treats a locale alias as a valid locale #18049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public function validate($value, Constraint $constraint)

$value = (string) $value;
$locales = Intl::getLocaleBundle()->getLocaleNames();
$aliases = Intl::getLocaleBundle()->getAliases();

if (!isset($locales[$value])) {
if (!isset($locales[$value]) && !in_array($value, $aliases)) {
$this->context->addViolation($constraint->message, array(
'{{ value }}' => $this->formatValue($value),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function getValidLocales()
array('pt'),
array('pt_PT'),
array('zh_Hans'),
array('fil_PH'),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"require-dev": {
"doctrine/common": "~2.3",
"symfony/http-foundation": "~2.1",
"symfony/intl": "~2.3",
"symfony/intl": "^2.3.21",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocaleBundle::getAliases() was introduced in Symfony 2.3.21. Without this tests with --prefer-lowest fail.

"symfony/yaml": "~2.0,>=2.0.5",
"symfony/config": "~2.2"
},
Expand Down