just some hours ago I've published a plugin with an awkward bug: it might print "1 votes"
This brought me to the following solution. Wherever a language specific string, depending on the numerus, might be used, it could be returned by the following function:
- Code: Select all
/**
* Returns $tx in its correct numerus according to $count.
*
* @param string $plugin The name of the plugin.
* @param string $tx The base name of the language string.
* @param int $count The item's count.
* @return string
*/
function XYZ_numerus($plugin, $tx, $count) {
global $plugin_tx;
$ptx = $plugin_tx[$plugin];
$limit = isset($ptx['paucal_limit']) ? $ptx['paucal_limit'] : 4;
$singular = isset($ptx[$tx.'_singular']) ? $ptx[$tx.'_singular'] : $ptx[$tx];
$paucal = isset($ptx[$tx.'_paucal']) ? $ptx[$tx.'_paucal']
: ($ptx[$tx.'_plural'] ? $ptx[$tx.'_plural'] : $ptx[$tx]);
$plural = isset($ptx[$tx.'_plural']) ? $ptx[$tx.'_plural'] : $ptx[$tx];
if ($count > $limit || $count == 0) {
return $plural;
} elseif ($count > 1) {
return $paucal;
} else {
return $singular;
}
}
It's important, that the XYZ will be replaced by the plugin's name (or some abbreviation), or the routine might be offered by some general utility plugin/addon. The benefits of using this routine: if no singular/paucal/plural is defined, a somewhat reasonable default will be used. So an english speaking developer might ignore the paucal (and even singular/plural forms) -- but the translator is able to introduce the paucal (singular/plural) afterwards. Additionally it's possible to set the upper limit for the paucal in the language file. The drawbacks: a somewhat slight decline of performance.
I'm very interested in your opinion about this function, and it's possible shortcommings (e.g. I'm not sure, if zero occurences use the plural form in all languages).
Christoph


