summaryrefslogtreecommitdiff
path: root/includes/common.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-01-21 22:44:25 +0000
committerDries Buytaert <dries@buytaert.net>2003-01-21 22:44:25 +0000
commit9a23223e253d95377123a9b4b49a54cc8cdbe744 (patch)
treef3817e25046234ada392e4c5ed1aa0d1177db454 /includes/common.inc
parentef0acbf2ddbfdfb8d639c317b82fa40daa6e1c5b (diff)
downloadbrdo-9a23223e253d95377123a9b4b49a54cc8cdbe744.tar.gz
brdo-9a23223e253d95377123a9b4b49a54cc8cdbe744.tar.bz2
- Applied Ori's format_plural() patch; see mailing list for details.
NOTE: some modules in the contributions repository might need to be updated.
Diffstat (limited to 'includes/common.inc')
-rw-r--r--includes/common.inc18
1 files changed, 16 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 9e27d9cd1..afc64fae3 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -552,8 +552,22 @@ function format_rss_item($title, $link, $description, $args = array()) {
return $output;
}
+/**
+ * Formats a string with a count of items so that the string is pluralized
+ * correctly.
+ * format_plural calls t() by itself, make sure not to pass already localized
+ * strings to it.
+ *
+ * @param $count The item count to display.
+ * @param $singular The string for the singular case. Please make sure it's clear
+ * this is singular, to ease translation. ("1 new comment" instead of
+ * "1 new").
+ * @param $plural The string for the plrual case. Please make sure it's clear
+ * this is plural, to ease translation. Use %count in places of the
+ * item count, as in "%count new comments".
+ */
function format_plural($count, $singular, $plural) {
- return ($count == 1) ? "$count ". t($singular) : "$count ". t($plural);
+ return t($count == 1 ? $singular : $plural, array("%count" => $count));
}
function format_size($size) {
@@ -628,7 +642,7 @@ function page_get_cache() {
}
function format_interval($timestamp) {
- $units = array("year|years" => 31536000, "week|weeks" => 604800, "day|days" => 86400, "hour|hours" => 3600, "min|min" => 60, "sec|sec" => 1);
+ $units = array("1 year|%count years" => 31536000, "1 week|%count weeks" => 604800, "1 day|%count days" => 86400, "1 hour|%count hours" => 3600, "1 min|%count min" => 60, "1 sec|%count sec" => 1);
foreach ($units as $key=>$value) {
$key = explode("|", $key);
if ($timestamp >= $value) {