Pārlūkot izejas kodu

[Translation] fixed message selector when the message is empty (closes #2144)

Fabien Potencier 13 gadi atpakaļ
vecāks
revīzija
c985ffaa99

+ 2 - 2
src/Symfony/Component/Translation/MessageSelector.php

@@ -54,9 +54,9 @@ class MessageSelector
         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;

+ 9 - 0
tests/Symfony/Tests/Component/Translation/MessageSelectorTest.php

@@ -39,8 +39,14 @@ class MessageSelectorTest extends \PHPUnit_Framework_TestCase
     {
         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),
@@ -53,6 +59,9 @@ class MessageSelectorTest extends \PHPUnit_Framework_TestCase
             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),
         );
     }
 }