Created
May 16, 2011 04:03
-
-
Save atma/973925 to your computer and use it in GitHub Desktop.
Russian (ukrainian) plural form
This file contains 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
<?php | |
/** | |
* @param int The number of items | |
* @param array Three item forms as for 1, 2-4(22,33), 5(66,78) respectively | |
*/ | |
function plural_form($n, $forms) | |
{ | |
$n = abs($n) % 100; | |
$n1 = $n % 10; | |
if ($n > 10 AND $n < 20) return $forms[2]; | |
if ($n1 > 1 AND $n1 < 5) return $forms[1]; | |
if ($n1 == 1) return $forms[0]; | |
return $forms[2]; | |
} | |
// Example usage | |
plural_form(1, array("месяц", "месяца", "месяцев")); // месяц | |
plural_form(32, array("месяц", "месяца", "месяцев")); // месяца | |
plural_form(15, array("месяц", "месяца", "месяцев")); // месяцев |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment