Created
August 13, 2019 12:08
-
-
Save sensonicm/da455832ceac565ac7083eb5813c7575 to your computer and use it in GitHub Desktop.
Russian plural function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function plural_str(i, str1, str2, str3){ | |
function plural (a){ | |
if ( a % 10 == 1 && a % 100 != 11 ) return 0 | |
else if ( a % 10 >= 2 && a % 10 <= 4 && ( a % 100 < 10 || a % 100 >= 20)) return 1 | |
else return 2; | |
} | |
switch (plural(i)) { | |
case 0: return str1; | |
case 1: return str2; | |
default: return str3; | |
} | |
} | |
example: | |
var num = 12; | |
plural_str(num, ‘товар’,'товара’,'товаров’); // 12 товаров |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment