Skip to content

Commit 55a0fef

Browse files
committed
Float support added for transchoice in the Translation Component
1 parent df308a4 commit 55a0fef

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/Symfony/Component/Translation/Interval.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ public static function getIntervalRegexp()
7575
{
7676
return <<<EOF
7777
({\s*
78-
(\-?\d+[\s*,\s*\-?\d+]*)
78+
(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)
7979
\s*})
8080
8181
|
8282
8383
(?P<left_delimiter>[\[\]])
8484
\s*
85-
(?P<left>-Inf|\-?\d+)
85+
(?P<left>-Inf|\-?\d+(\.\d+)?)
8686
\s*,\s*
87-
(?P<right>\+?Inf|\-?\d+)
87+
(?P<right>\+?Inf|\-?\d+(\.\d+)?)
8888
\s*
8989
(?P<right_delimiter>[\[\]])
9090
EOF;
@@ -98,6 +98,6 @@ private static function convertNumber($number)
9898
return -log(0);
9999
}
100100

101-
return (int) $number;
101+
return (float) $number;
102102
}
103103
}

src/Symfony/Component/Translation/Tests/MessageSelectorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public function getChooseTests()
6767
array('There are %count% apples', 'There is one apple|There are %count% apples', 0),
6868
array('There is one apple', 'There is one apple|There are %count% apples', 1),
6969
array('There are %count% apples', 'There is one apple|There are %count% apples', 2),
70+
71+
// Tests for float numbers
72+
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),
73+
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),
74+
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),
75+
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),
76+
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),
77+
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),
7078
);
7179
}
7280
}

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function transChoice($id, $number, array $parameters = array(), $domain =
157157
}
158158
}
159159

160-
return strtr($this->selector->choose($catalogue->get($id, $domain), (int) $number, $locale), $parameters);
160+
return strtr($this->selector->choose($catalogue->get($id, $domain), (float) $number, $locale), $parameters);
161161
}
162162

163163
protected function loadCatalogue($locale)

0 commit comments

Comments
 (0)