airbnb / polyglot.js

Give your JavaScript the ability to speak many languages.
http://airbnb.github.io/polyglot.js
BSD 2-Clause "Simplified" License
3.71k stars 208 forks source link

Fixes plurals for russian when number is greater than 100 #119

Closed bullgare closed 6 years ago

bullgare commented 6 years ago

You can check with numbers like 512 vs just 12

bullgare commented 6 years ago

It is a fix for change made in this PR - https://github.com/airbnb/polyglot.js/commit/2a88a79c92c13c20936463da7c2738ad2331c758

bullgare commented 6 years ago

It fixes a small issue on numbers like 112

viatsko commented 6 years ago

I can confirm that PR implements indeed a correct behavior for the Slavic family (https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals)

Plural rule 7 (3 forms) Families: Slavic (Belarusian, Bosnian, Croatian, Serbian, Russian, Ukrainian) ends in 1, excluding 11: 1, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 131, 141, 151, 161, 171, 181, 191, 201, 221, 231, 241, 251, 261, 271, 281, 291, … ends in 2-4, excluding 12-14: 2, 3, 4, 22, 23, 24, 32, 33, 34, 42, 43, 44, 52, 53, 54, 62, 63, 64, 72, 73, 74, 82, 83, 84, 92, 93, 94, 102, 103, 104, 122, 123, 124, 132, 133, 134, 142, 143, 144, 152, 153, 154, 162, 163, 164, 172, 173, 174, 182, 183, … everything else: 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 45, 46, 47, 48, 49, 50, 55, 56, 57, 58, 59, 60, 65, 66, 67, 68, 69, 70, 75, 76, 77, …

bullgare commented 6 years ago

@viatsko I've checked you url. The problem is that they say nothing about numbers like 112, 212 and so on. I'm from Russia and I've run into this problem on a real site. It looks odd. The canonical form of pluralization for russian looks like this:

nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);

But I don't like that string as it's really hard to read. You can see here that they always use remainder of division by 100. And mozilla's doc is missing it, I guess.

bullgare commented 6 years ago

Fast search gave me this doc. But not sure how respected it is comparing to mozilla's site: https://github.com/translate/l10n-guide/blob/master/docs/l10n/pluralforms.rst

bullgare commented 6 years ago

I've made a request for change on mozilla's site as well. https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals$revision/1395551

viatsko commented 6 years ago

Yup, that's true, MDN misses clarification on what to do with numbers above 100

And I'm also Russian native so that's why I'm confirming I've had the same issue with the original version 👍

ljharb commented 6 years ago

Additionally, I would want to see credible resources that describe this numbering requirement - ideally http://www.unicode.org/cldr/charts/33/supplemental/language_plural_rules.html which i consider the source of truth.

bullgare commented 6 years ago

As you can see here - http://www.unicode.org/cldr/charts/33/supplemental/language_plural_rules.html#ru, it always depends on remainder of division by 100.

bullgare commented 6 years ago

@ljharb I'm not an expert in that languages. And I made changes to the exact same files that were changed in this commit - https://github.com/airbnb/polyglot.js/commit/2a88a79c92c13c20936463da7c2738ad2331c758. What should we do? Should we ask for help from someone else?

viatsko commented 6 years ago

I believe it's safe to assume pluralization rules would match according to the bottom of the table

See http://www.unicode.org/cldr/charts/33/supplemental/language_plural_rules.html#ru:

screen shot 2018-07-15 at 20 49 05

(Serbian and Russian groups)

bullgare commented 6 years ago

Great! Thanks