Float support added for transchoice in the Translation Component

This commit is contained in:
Nicolas Schwartz 2012-11-01 23:19:52 +01:00
parent df308a4fca
commit 55a0fef233
3 changed files with 13 additions and 5 deletions

View File

@ -75,16 +75,16 @@ class Interval
{
return <<<EOF
({\s*
(\-?\d+[\s*,\s*\-?\d+]*)
(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)
\s*})
|
(?P<left_delimiter>[\[\]])
\s*
(?P<left>-Inf|\-?\d+)
(?P<left>-Inf|\-?\d+(\.\d+)?)
\s*,\s*
(?P<right>\+?Inf|\-?\d+)
(?P<right>\+?Inf|\-?\d+(\.\d+)?)
\s*
(?P<right_delimiter>[\[\]])
EOF;
@ -98,6 +98,6 @@ EOF;
return -log(0);
}
return (int) $number;
return (float) $number;
}
}

View File

@ -67,6 +67,14 @@ class MessageSelectorTest extends \PHPUnit_Framework_TestCase
array('There are %count% apples', 'There is one apple|There are %count% apples', 0),
array('There is one apple', 'There is one apple|There are %count% apples', 1),
array('There are %count% apples', 'There is one apple|There are %count% apples', 2),
// Tests for float numbers
array('There is almost one apple', '{0} There is no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7),
array('There is one apple', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1),
array('There is more than one apple', '{0} There is no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7),
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),
);
}
}

View File

@ -157,7 +157,7 @@ class Translator implements TranslatorInterface
}
}
return strtr($this->selector->choose($catalogue->get($id, $domain), (int) $number, $locale), $parameters);
return strtr($this->selector->choose($catalogue->get($id, $domain), (float) $number, $locale), $parameters);
}
protected function loadCatalogue($locale)