merged branch nicoschwartz/translation_transchoice_float_support (PR #5890)
This PR was merged into the master branch.
Commits
-------
55a0fef
Float support added for transchoice in the Translation Component
Discussion
----------
Float support added for transchoice in the Translation Component
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT
---------------------------------------------------------------------------
by pborreli at 2012-11-01T23:22:50Z
👍 nice PR
This commit is contained in:
commit
f3acc069cd
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user