function _flag_format_plural in Flag 5
Same name and namespace in other branches
- 6 flag.module \_flag_format_plural()
Format a string containing a count of items.
_flag_format_plural() is a version of format_plural() which accepts the format string as a single argument, where the singular and plural forms are separated by pipe. A 'zero' form is allowed as well.
_flag_format_plural() is used where we want the admin, not the programmer, to be able to nicely and easily format a number.
If three forms are provided, separated by pipes, then the first is considered the zero form and is used if $count is 0. The zero form may well be an empty string.
"@count"
"1 vote|@count votes"
"needs voting|1 vote|@count votes"
"|1 vote|@count votes"
"|@count|@count"
Parameters
$count: The item count to display.
$format: The singular, plural, and optionally the zero, forms separated by pipe characters.
Return value
A formatted, translated string.
Examples for $format:
1 call to _flag_format_plural()
- flag_field_handler_count in includes/
flag.views.inc - Handler that prints the 'count' field in a zero/singular/plural phrase, localizable.
File
- ./
flag.module, line 786 - The Flag module.
Code
function _flag_format_plural($count, $format) {
$elements = explode('|', $format ? $format : '@count', 3);
if (count($elements) == 3) {
list($zero, $singular, $plural) = $elements;
}
elseif (count($elements) == 2) {
list($singular, $plural) = $elements;
$zero = NULL;
}
else {
// count($elements) == 1
$singular = $plural = $elements[0];
$zero = NULL;
}
if (isset($zero) && intval($count) == 0) {
return $zero;
}
else {
return format_plural(intval($count), $singular, $plural);
}
}