I think that we all ran into a problem before the application reports that there is a “1 minute” or something like that. I think this observation indicates that many programmers ignore this problem.
In my projects, I usually did something in this direction to take into account pluralizing nouns:
$Count = count($Items); $Noun = 'minute'; if ($Count != 1) { $Noun .= 's'; } echo sprintf('There are %u %s remaining.', $Count, $Noun);
I have a couple of questions with this approach:
- It places a burden on the programmer to perform this pluralization check every time a line is needed, so the code can never be reused.
- It uselessly inflates application code and prohibits readability.
- This is not common. The example worked because “minutes” is the plural of “minute”. What about "sheep", "bulls" or "mushrooms"?
Does anyone have any ideas for a universal, modular approach to solving this problem? I am fine with the fact that there is more than one answer.
source share