diff --git a/src/Symfony/Component/Translation/MessageSelector.php b/src/Symfony/Component/Translation/MessageSelector.php index 387c964d0d3f9..c103c210a3b6e 100644 --- a/src/Symfony/Component/Translation/MessageSelector.php +++ b/src/Symfony/Component/Translation/MessageSelector.php @@ -44,8 +44,6 @@ class MessageSelector * * @return string * - * @throws \InvalidArgumentException - * * @api */ public function choose($message, $number, $locale) @@ -74,7 +72,7 @@ public function choose($message, $number, $locale) $position = PluralizationRules::get($number, $locale); if (!isset($standardRules[$position])) { - throw new \InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale)); + return current($standardRules); } return $standardRules[$position]; diff --git a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php index 74956294a122a..dcff5261b9e4c 100644 --- a/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php +++ b/src/Symfony/Component/Translation/Tests/MessageSelectorTest.php @@ -25,16 +25,6 @@ public function testChoose($expected, $id, $number) $this->assertEquals($expected, $selector->choose($id, $number, 'en')); } - /** - * @expectedException InvalidArgumentException - */ - public function testChooseWhenNoEnoughChoices() - { - $selector = new MessageSelector(); - - $selector->choose('foo', 10, 'en'); - } - public function getChooseTests() { return array( @@ -75,6 +65,9 @@ public function getChooseTests() array('There is no apples', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0), array('There is no apples', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0), array('There is no apples', '{0.0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0), + + // #4228 + array('There are %count% apples', 'There are %count% apples', 10), ); } } diff --git a/src/Symfony/Component/Translation/Tests/TranslatorTest.php b/src/Symfony/Component/Translation/Tests/TranslatorTest.php index ac8a35e72f7a2..b1f1e4d7617bf 100644 --- a/src/Symfony/Component/Translation/Tests/TranslatorTest.php +++ b/src/Symfony/Component/Translation/Tests/TranslatorTest.php @@ -263,16 +263,13 @@ public function testTransChoiceFallbackBis() $this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10))); } - /** - * @expectedException \InvalidArgumentException - */ public function testTransChoiceFallbackWithNoTranslation() { $translator = new Translator('ru', new MessageSelector()); $translator->setFallbackLocale('en'); $translator->addLoader('array', new ArrayLoader()); - $this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10))); + $this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, array('%count%' => 10))); } }