8000 Added locale option for intl form types. · symfony/symfony@7d0476b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d0476b

Browse files
committed
Added locale option for intl form types.
1 parent 7695112 commit 7d0476b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Component/Form/Extension/Core/Type/CountryType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class CountryType extends AbstractType implements ChoiceLoaderInterface
3131
*/
3232
private $choiceList;
3333

34+
private $locale;
35+
3436
/**
3537
* {@inheritdoc}
3638
*/
@@ -44,9 +46,12 @@ public function configureOptions(OptionsResolver $resolver)
4446
return null;
4547
}
4648

49+
$this->locale = $options['locale'];
50+
4751
return $this;
4852
},
4953
'choice_translation_domain' => false,
54+
'locale' => \Locale::getDefault(),
5055
));
5156
}
5257

@@ -75,7 +80,7 @@ public function loadChoiceList($value = null)
7580
return $this->choiceList;
7681
}
7782

78-
return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getRegionBundle()->getCountryNames()), $value);
83+
return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getRegionBundle()->getCountryNames($this->locale)), $value);
7984
}
8085

8186
/**

src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,17 @@ public function testSubmitNull($expected = null, $norm = null, $view = null)
5656
{
5757
parent::testSubmitNull($expected, $norm, '');
5858
}
59+
60+
public function testCustomLocale()
61+
{
62+
$choices = $this->factory->create(static::TESTED_TYPE, null, array('locale' => 'ru'))
63+
->createView()->vars['choices'];
64+
65+
// Don't check objects for identity
66+
$this->assertContains(new ChoiceView('DE', 'DE', 'Германия'), $choices, '', false, false);
67+
$this->assertContains(new ChoiceView('GB', 'GB', 'Великобритания'), $choices, '', false, false);
68+
$this->assertContains(new ChoiceView('US', 'US', 'Соединенные Штаты'), $choices, '', false, false);
69+
$this->assertContains(new ChoiceView('FR', 'FR', 'Франция'), $choices, '', false, false);
70+
$this->assertContains(new ChoiceView('MY', 'MY', 'Малайзия'), $choices, '', false, false);
71+
}
5972
}

0 commit comments

Comments
 (0)
0