diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php index 02e8e09cdc824..f544f980c239c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php @@ -31,6 +31,8 @@ class CountryType extends AbstractType implements ChoiceLoaderInterface */ private $choiceList; + private $locale; + /** * {@inheritdoc} */ @@ -44,9 +46,12 @@ public function configureOptions(OptionsResolver $resolver) return null; } + $this->locale = $options['locale']; + return $this; }, 'choice_translation_domain' => false, + 'locale' => \Locale::getDefault(), )); } @@ -75,7 +80,7 @@ public function loadChoiceList($value = null) return $this->choiceList; } - return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getRegionBundle()->getCountryNames()), $value); + return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getRegionBundle()->getCountryNames($this->locale)), $value); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php b/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php index 990235c10a99a..18d93e9c8731e 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php @@ -31,6 +31,8 @@ class CurrencyType extends AbstractType implements ChoiceLoaderInterface */ private $choiceList; + private $locale; + /** * {@inheritdoc} */ @@ -44,9 +46,12 @@ public function configureOptions(OptionsResolver $resolver) return null; } + $this->locale = $options['locale']; + return $this; }, 'choice_translation_domain' => false, + 'locale' => \Locale::getDefault(), )); } @@ -75,7 +80,7 @@ public function loadChoiceList($value = null) return $this->choiceList; } - return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getCurrencyBundle()->getCurrencyNames()), $value); + return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getCurrencyBundle()->getCurrencyNames($this->locale)), $value); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php index 2137c65a9e440..6207bcdca8839 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php @@ -31,6 +31,8 @@ class LanguageType extends AbstractType implements ChoiceLoaderInterface */ private $choiceList; + private $locale; + /** * {@inheritdoc} */ @@ -44,9 +46,12 @@ public function configureOptions(OptionsResolver $resolver) return null; } + $this->locale = $options['locale']; + return $this; }, 'choice_translation_domain' => false, + 'locale' => \Locale::getDefault(), )); } @@ -75,7 +80,7 @@ public function loadChoiceList($value = null) return $this->choiceList; } - return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getLanguageBundle()->getLanguageNames()), $value); + return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getLanguageBundle()->getLanguageNames($this->locale)), $value); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php index 38e62af060d98..91031865a06aa 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php @@ -31,6 +31,8 @@ class LocaleType extends AbstractType implements ChoiceLoaderInterface */ private $choiceList; + private $locale; + /** * {@inheritdoc} */ @@ -44,9 +46,12 @@ public function configureOptions(OptionsResolver $resolver) return null; } + $this->locale = $options['locale']; + return $this; }, 'choice_translation_domain' => false, + 'locale' => \Locale::getDefault(), )); } @@ -75,7 +80,7 @@ public function loadChoiceList($value = null) return $this->choiceList; } - return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getLocaleBundle()->getLocaleNames()), $value); + return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getLocaleBundle()->getLocaleNames($this->locale)), $value); } /** diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index 5f9af3e1c1b27..961e966e6eb7e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -56,4 +56,17 @@ public function testSubmitNull($expected = null, $norm = null, $view = null) { parent::testSubmitNull($expected, $norm, ''); } + + public function testCustomLocale() + { + $choices = $this->factory->create(static::TESTED_TYPE, null, array('locale' => 'ru')) + ->createView()->vars['choices']; + + // Don't check objects for identity + $this->assertContains(new ChoiceView('DE', 'DE', 'Германия'), $choices, '', false, false); + $this->assertContains(new ChoiceView('GB', 'GB', 'Великобритания'), $choices, '', false, false); + $this->assertContains(new ChoiceView('US', 'US', 'Соединенные Штаты'), $choices, '', false, false); + $this->assertContains(new ChoiceView('FR', 'FR', 'Франция'), $choices, '', false, false); + $this->assertContains(new ChoiceView('MY', 'MY', 'Малайзия'), $choices, '', false, false); + } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php index be9264d7b19db..acffd10327a34 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CurrencyTypeTest.php @@ -35,6 +35,16 @@ public function testCurrenciesAreSelectable() $this->assertContains(new ChoiceView('SIT', 'SIT', 'Slovenian Tolar'), $choices, '', false, false); } + public function testCustomLocale() + { + $choices = $this->factory->create(static::TESTED_TYPE, null, array('locale' => 'ru')) + ->createView()->vars['choices']; + + $this->assertContains(new ChoiceView('EUR', 'EUR', 'Евро'), $choices, '', false, false); + $this->assertContains(new ChoiceView('USD', 'USD', 'Доллар США'), $choices, '', false, false); + $this->assertContains(new ChoiceView('SIT', 'SIT', 'Словенский толар'), $choices, '', false, false); + } + public function testSubmitNull($expected = null, $norm = null, $view = null) { parent::testSubmitNull($expected, $norm, ''); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php index 5ea3c4a732165..d3c8ef8ff9af1 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php @@ -37,6 +37,18 @@ public function testCountriesAreSelectable() $this->assertContains(new ChoiceView('my', 'my', 'Burmese'), $choices, '', false, false); } + public function testCustomLocale() + { + $choices = $this->factory->create(static::TESTED_TYPE, null, array('locale' => 'ru')) + ->createView()->vars['choices']; + + $this->assertContains(new ChoiceView('en', 'en', 'Английский'), $choices, '', false, false); + $this->assertContains(new ChoiceView('en_GB', 'en_GB', 'Британский английский'), $choices, '', false, false); + $this->assertContains(new ChoiceView('en_US', 'en_US', 'Американский английский'), $choices, '', false, false); + $this->assertContains(new ChoiceView('fr', 'fr', 'Французский'), $choices, '', false, false); + $this->assertContains(new ChoiceView('my', 'my', 'Бирманский'), $choices, '', false, false); + } + public function testMultipleLanguagesIsNotIncluded() { $choices = $this->factory->create(static::TESTED_TYPE, 'language') diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php index 58b94517d4572..1dd310dbc3acf 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php @@ -35,6 +35,16 @@ public function testLocalesAreSelectable() $this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false); } + public function testCustomLocale() + { + $choices = $this->factory->create(static::TESTED_TYPE, null, array('locale' => 'ru')) + ->createView()->vars['choices']; + + $this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false); + $this->assertContains(new ChoiceView('en_GB', 'en_GB', 'English (United Kingdom)'), $choices, '', false, false); + $this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'Chinese (Traditional, Macau SAR China)'), $choices, '', false, false); + } + public function testSubmitNull($expected = null, $norm = null, $view = null) { parent::testSubmitNull($expected, $norm, '');