Skip to content

[Translation] Floating number plural broken #30215

Closed
@kylekatarnls

Description

@kylekatarnls

Symfony version(s) affected: 4.2.3

Description
Decimal number between 1 and 2 produces incorrect plural in English.

How to reproduce

$t = new \Symfony\Component\Translation\Translator('en');

$t->addLoader('array', new \Symfony\Component\Translation\Loader\ArrayLoader());
$t->addResource('array', [
    'liter' => '%count% liter|%count% liters',
], 'en');

echo $t->trans('liter', ['%count%' => 1.5]);

echo "\n";

$t = new \Symfony\Component\Translation\Translator('fr');

$t->addLoader('array', new \Symfony\Component\Translation\Loader\ArrayLoader());
$t->addResource('array', [
    'liter' => '%count% litre|%count% litres',
], 'fr');

echo $t->trans('liter', ['%count%' => 1.5]);

It outputs:

1.5 liter
1.5 litre

It should output:

1.5 liters
1.5 litre

Possible Solution
int typing here should be removed, it's a float, numbers should not be truncated:

private function getPluralizationRule(int $number, string $locale): int

Related to #16256

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions