8000 How to get correct plural forms for fractions · Issue #10671 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

How to get correct plural forms for fractions #10671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
icywolfy opened this issue Apr 9, 2014 · 5 comments
Closed

How to get correct plural forms for fractions #10671

icywolfy opened this issue Apr 9, 2014 · 5 comments

Comments

@icywolfy
Copy link
icywolfy commented Apr 9, 2014

Is there any means of getting the correct plural forms selected for fractions?

ie:
"%count% Tag|%count% Tage"
should render
1 Tag
1,0 Tage
1,5 Tage

French seems to work by chance:
"%count% jour|%count% jours"
1 jour
1,0 jour
1,5 jour

@mayeco
Copy link
Contributor
mayeco commented Apr 10, 2014

This is not a Issue is a question, you should create a question in http://stackoverflow.com and tagged with symfony2

@icywolfy
Copy link
Author

Let me rephrase that then.

In the function MessageSelector::choose() method
When providing a number that doesn't match a given range, it falls back to

        $position = PluralizationRules::get($number, $locale);

Class PluralizationRules cannot handle fractions.
For the language 'de' it evaluates

return ($number == 1) ? 0 : 1;

Thus, by default, the Translation component cannot handle fractional values properly.
The correct value would take "1.0" with the plural, but "1" as the singular.

Similarily, for the french 'fr' locale
Fractional values between 0 and 2; are singular,
Fractional values between 2 and +inf are plural.

For the Russian Locale, the resultant value returns 0, 1, or 2.
However, there are 4 unique plural cases required to adequately represent the language.
As for fractional values, whether you use case 0 or case 1 depends on the word, thus, requires a unique 4th form to be programatically determinant.

Bosnian requires casing based on the value of the fraction
za 1 mjesec
za 0,1 mjesec
za 2 mjeseca
za 0,2 mjeseca
za 5 mjeseci
za 0,5 mjeseci

It seems odd that the default casing provided by symfony framework when on a recent system, the built in MessageFormatter class provided by ext-intl in PHP works as expected

foreach (array(1, 2, 5, 1.1, 1.2, 1.5) as $num) { 
  echo MessageFormatter::formatMessage("hr", "{count, plural, one{# one} few{# few} many{# many} other{# other}}", array("count"=>$num)), PHP_EOL;
}
// output:
1 one
2 few
5 other
1,1 one
1,2 few
1,5 other

And 8000 it would be nice to not have to rely on ext-intl being installed as it is not enabled by default on PHP 5.3/5.4/5.5

@stof
Copy link
Member
stof commented Apr 10, 2014

We already have an issue suggesting to use the MessageFormatter class: #6009

@javiereguiluz
Copy link
Member

@stof maybe we should close this issue? As you said, #6009 seems like a generic version of this issue.

@fabpot
Copy link
Member
fabpot commented Dec 29, 2014

Closing in favor of #6009

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0