8000 Falling back to first translation if no choice available · symfony/symfony@69206bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 69206bb

Browse files
committed
Falling back to first translation if no choice available
1 parent 8729026 commit 69206bb

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

src/Symfony/Component/Translation/MessageSelector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function choose($message, $number, $locale)
7474

7575
$position = PluralizationRules::get($number, $locale);
7676
if (!isset($standardRules[$position])) {
77-
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));
77+
return current($standardRules);
7878
}
7979

8080
return $standardRules[$position];

src/Symfony/Component/Translation/Tests/MessageSelectorTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ public function testChoose($expected, $id, $number)
2525
$this->assertEquals($expected, $selector->choose($id, $number, 'en'));
2626
}
2727

28-
/**
29-
* @expectedException InvalidArgumentException
30-
*/
31-
public function testChooseWhenNoEnoughChoices()
32-
{
33-
$selector = new MessageSelector();
34-
35-
$selector->choose('foo', 10, 'en');
36-
}
37-
3828
public function getChooseTests()
3929
{
4030
return array(
@@ -75,6 +65,9 @@ public function getChooseTests()
7565
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),
7666
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),
7767
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),
68+
69+
// #4228
70+
array('There are %count% apples', 'There are %count% apples', 10),
7871
);
7972
}
8073
}

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,13 @@ public function testTransChoiceFallbackBis()
263263
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
264264
}
265265

266-
/**
267-
* @expectedException \InvalidArgumentException
268-
*/
269266
public function testTransChoiceFallbackWithNoTranslation()
270267
{
271268
$translator = new Translator('ru', new MessageSelector());
272269
$translator->setFallbackLocale('en');
273270
$translator->addLoader('array', new ArrayLoader());
274271

275-
$this->assertEquals('10 things', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
272+
$this->assertEquals('some_message2', $translator->transChoice('some_message2', 10, array('%count%' => 10)));
276273
}
277274
}
278275

0 commit comments

Comments
 (0)
0