Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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

:+1: nice PR
  • Loading branch information
fabpot committed Nov 6, 2012
2 parents 1b53bf6 + 55a0fef commit f3acc06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Component/Translation/Interval.php
Expand Up @@ -75,16 +75,16 @@ public static function getIntervalRegexp()
{
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;
Expand All @@ -98,6 +98,6 @@ private static function convertNumber($number)
return -log(0);
}

return (int) $number;
return (float) $number;
}
}
Expand Up @@ -67,6 +67,14 @@ public function getChooseTests()
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),
);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Translator.php
Expand Up @@ -157,7 +157,7 @@ public function transChoice($id, $number, array $parameters = array(), $domain =
}
}

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)
Expand Down

0 comments on commit f3acc06

Please sign in to comment.