Skip to content

Commit c985ffa

Browse files
committed
[Translation] fixed message selector when the message is empty (closes #2144)
1 parent 55eaf4e commit c985ffa

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Symfony/Component/Translation/MessageSelector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function choose($message, $number, $locale)
5454
foreach ($parts as $part) {
5555
$part = trim($part);
5656

57-
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s+(?P<message>.+?)$/x', $part, $matches)) {
57+
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/x', $part, $matches)) {
5858
$explicitRules[$matches['interval']] = $matches['message'];
59-
} elseif (preg_match('/^\w+\: +(.+)$/', $part, $matches)) {
59+
} elseif (preg_match('/^\w+\:\s*(.*?)$/', $part, $matches)) {
6060
$standardRules[] = $matches[1];
6161
} else {
6262
$standardRules[] = $part;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ public function getChooseTests()
3939
{
4040
return array(
4141
array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
42+
array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
43+
array('There is no apples', '{0}There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
44+
4245
array('There is one apple', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 1),
46+
4347
array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10),
48+
array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf]There is %count% apples', 10),
49+
array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10),
4450

4551
array('There is %count% apples', 'There is one apple|There is %count% apples', 0),
4652
array('There is one apple', 'There is one apple|There is %count% apples', 1),
@@ -53,6 +59,9 @@ public function getChooseTests()
5359
array('There is no apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 0),
5460
array('There is one apple', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 1),
5561
array('There is %count% apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 10),
62+
63+
array('', '{0}|{1} There is one apple|]1,Inf] There is %count% apples', 0),
64+
array('', '{0} There is no apples|{1}|]1,Inf] There is %count% apples', 1),
5665
);
5766
}
5867
}

0 commit comments

Comments
 (0)