Quite often on sites there are ridiculous verbal constructions with which the impersonal programmer wanted to show some quantitative parameter, for example:
on site 22 people (and should be 22 people)
1 comments (it is clear that the calculation went on 10+ comments, but this is not an option)
But actually this is not a problem!
In order to do everything beautifully, quite a bit of code is enough
')
class datext {
public static function proceedTextual ($ numeric, $ many, $ one, $ two)
{
$ numeric = (int) abs ($ numeric);
if ((numeric% 100 == 1 || ($ numeric% 100> 20) && ($ numeric% 10 == 1)) return $ one;
if ($ numeric% 100 == 2 || ($ numeric% 100> 20) && ($ numeric% 10 == 2)) return $ two;
if ($ numeric% 100 == 3 || ($ numeric% 100> 20) && ($ numeric% 10 == 3)) return $ two;
if ($ numeric% 100 == 4 || ($ numeric% 100> 20) && ($ numeric% 10 == 4)) return $ two;
return $ many;
}
}
The function has been introduced into the class, so that God forbid that the name with the one already used does not intersect.
Static is made so that you do not need to create an instance of the class.
And now examples:
echo "21" .datext :: proceedTextual (21, "comments", "comment", "comment");
at the output we get "
21 comments "
echo "online 152" .datext :: proceedTextual (152, 'person', 'person', 'person');
at the output we get "
online 152 people "
update:Thank you
khim for providing other solutions to the issue:
1.
pluralforms2.
gettext