Created
February 11, 2012 06:34
-
-
Save spiculator/1797308 to your computer and use it in GitHub Desktop.
getmul
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
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
sub getmul($$$$) { | |
my $num = shift; | |
my $num2 = $num % 100; | |
my $last = $num2 % 10; | |
my $case = $num2 > 4 && $num2 < 21 ? 2 : | |
1 == $last ? 0 : | |
$last > 1 && $last < 5 ? 1 | |
: 2; | |
return sprintf "%d %s", $num, $_[$case]; | |
} | |
printf "%s\n", getmul 122, "услуга", "услуги", "услуг"; | |
printf "%s\n", getmul 38, "попугай", "попугая", "попугаев"; | |
printf "%s\n", getmul 33, "год", "года", "лет"; | |
printf "%s\n", getmul 1001, "ночь", "ночи", "ночей"; | |
__END__ | |
sergey@athlon:/tmp$ ./mul.pl | |
122 услуги | |
38 попугаев | |
33 года | |
1001 ночь |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same thing in gettext: http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms