Skip to content

Commit

Permalink
[Translation] fixed message selector when the message is empty (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 14, 2011
1 parent 55eaf4e commit c985ffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Translation/MessageSelector.php
Expand Up @@ -54,9 +54,9 @@ public function choose($message, $number, $locale)
foreach ($parts as $part) {
$part = trim($part);

if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s+(?P<message>.+?)$/x', $part, $matches)) {
if (preg_match('/^(?P<interval>'.Interval::getIntervalRegexp().')\s*(?P<message>.*?)$/x', $part, $matches)) {
$explicitRules[$matches['interval']] = $matches['message'];
} elseif (preg_match('/^\w+\: +(.+)$/', $part, $matches)) {
} elseif (preg_match('/^\w+\:\s*(.*?)$/', $part, $matches)) {
$standardRules[] = $matches[1];
} else {
$standardRules[] = $part;
Expand Down
Expand Up @@ -39,8 +39,14 @@ public function getChooseTests()
{
return array(
array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
array('There is no apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),
array('There is no apples', '{0}There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 0),

array('There is one apple', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 1),

array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10),
array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf]There is %count% apples', 10),
array('There is %count% apples', '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples', 10),

array('There is %count% apples', 'There is one apple|There is %count% apples', 0),
array('There is one apple', 'There is one apple|There is %count% apples', 1),
Expand All @@ -53,6 +59,9 @@ public function getChooseTests()
array('There is no apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 0),
array('There is one apple', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 1),
array('There is %count% apples', '{0} There is no apples|one: There is one apple|more: There is %count% apples', 10),

array('', '{0}|{1} There is one apple|]1,Inf] There is %count% apples', 0),
array('', '{0} There is no apples|{1}|]1,Inf] There is %count% apples', 1),
);
}
}

0 comments on commit c985ffa

Please sign in to comment.