diff --git a/includes/common.inc b/includes/common.inc
index 9e27d9cd19af..afc64fae369c 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) {
diff --git a/modules/aggregator.module b/modules/aggregator.module
index 77c49bc0d0c1..0a9c79901c63 100644
--- a/modules/aggregator.module
+++ b/modules/aggregator.module
@@ -405,7 +405,7 @@ function import_view() {
$header = array(t("title"), t("attributes"), t("items"), t("last update"), t("next update"), array("data" => t("operations"), "colspan" => 3));
unset($rows);
while ($feed = db_fetch_object($result)) {
- $rows[] = array($feed->title, $feed->attributes, format_plural($feed->items, "item", "items"), ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never"), ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never"), l(t("edit feed"), "admin/import/edit/feed/$feed->fid"), l(t("remove items"), "admin/import/remove/$feed->fid"), l(t("update items"), "admin/import/update/$feed->fid"));
+ $rows[] = array($feed->title, $feed->attributes, format_plural($feed->items, "1 item", "%count items"), ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never"), ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never"), l(t("edit feed"), "admin/import/edit/feed/$feed->fid"), l(t("remove items"), "admin/import/remove/$feed->fid"), l(t("update items"), "admin/import/update/$feed->fid"));
}
$output .= table($header, $rows);
diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module
index 77c49bc0d0c1..0a9c79901c63 100644
--- a/modules/aggregator/aggregator.module
+++ b/modules/aggregator/aggregator.module
@@ -405,7 +405,7 @@ function import_view() {
$header = array(t("title"), t("attributes"), t("items"), t("last update"), t("next update"), array("data" => t("operations"), "colspan" => 3));
unset($rows);
while ($feed = db_fetch_object($result)) {
- $rows[] = array($feed->title, $feed->attributes, format_plural($feed->items, "item", "items"), ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never"), ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never"), l(t("edit feed"), "admin/import/edit/feed/$feed->fid"), l(t("remove items"), "admin/import/remove/$feed->fid"), l(t("update items"), "admin/import/update/$feed->fid"));
+ $rows[] = array($feed->title, $feed->attributes, format_plural($feed->items, "1 item", "%count items"), ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never"), ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never"), l(t("edit feed"), "admin/import/edit/feed/$feed->fid"), l(t("remove items"), "admin/import/remove/$feed->fid"), l(t("update items"), "admin/import/update/$feed->fid"));
}
$output .= table($header, $rows);
diff --git a/modules/cloud.module b/modules/cloud.module
index 78bd24b882a6..f7d88615430a 100644
--- a/modules/cloud.module
+++ b/modules/cloud.module
@@ -143,14 +143,14 @@ function cloud_list($limit = 10) {
$hour = floor((time() - $site->timestamp) / 3600);
if ($hour < 12) {
if ($hour == 0) {
- $output .= "
". t("Updated < 1 hours ago:");
+ $output .= "
". t("Updated less than one hour ago:");
}
else {
- $output .= "
". t("Updated %a ago:", array("%a" => format_plural($hour, "hour", "hours")));
+ $output .= "
". format_plural($hour, "Updated an hour ago:", "Updated %count hours ago:");
}
}
else if ($list) {
- $output .= "
". t("Updated more than %a ago:", array("%a" => format_plural($hour, "hour", "hours")));
+ $output .= "
". format_plural($hour, "Updated more than an hour ago:", "Updated more than %count hours ago:");
$list = 0;
}
}
diff --git a/modules/comment.module b/modules/comment.module
index 38c5b3c80084..d1afd7cd469a 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -621,10 +621,10 @@ function comment_link($type, $node = 0, $main = 0) {
$new = comment_num_new($node->nid);
if ($all) {
- $links[] = l(format_plural($all, "comment", "comments"), "node/view/$node->nid#comment", array("title" => t('Jump to first comment of this posting.')));
+ $links[] = l(format_plural($all, "1 comment", "%count comments"), "node/view/$node->nid#comment", array("title" => t("Jump to the first comment of this posting.")));
if ($new) {
- $links[] = l("$new ". t("new"), "node/view/$node->nid#new", array("title" => t('Jump to first new comment of this posting.')));
+ $links[] = l(format_plural($new, "1 new comment", "%count new comments"), "node/view/$node->nid#new", array("title" => t("Jump to the first new comment of this posting.")));
}
}
else {
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 38c5b3c80084..d1afd7cd469a 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -621,10 +621,10 @@ function comment_link($type, $node = 0, $main = 0) {
$new = comment_num_new($node->nid);
if ($all) {
- $links[] = l(format_plural($all, "comment", "comments"), "node/view/$node->nid#comment", array("title" => t('Jump to first comment of this posting.')));
+ $links[] = l(format_plural($all, "1 comment", "%count comments"), "node/view/$node->nid#comment", array("title" => t("Jump to the first comment of this posting.")));
if ($new) {
- $links[] = l("$new ". t("new"), "node/view/$node->nid#new", array("title" => t('Jump to first new comment of this posting.')));
+ $links[] = l(format_plural($new, "1 new comment", "%count new comments"), "node/view/$node->nid#new", array("title" => t("Jump to the first new comment of this posting.")));
}
}
else {
diff --git a/modules/import.module b/modules/import.module
index 77c49bc0d0c1..0a9c79901c63 100644
--- a/modules/import.module
+++ b/modules/import.module
@@ -405,7 +405,7 @@ function import_view() {
$header = array(t("title"), t("attributes"), t("items"), t("last update"), t("next update"), array("data" => t("operations"), "colspan" => 3));
unset($rows);
while ($feed = db_fetch_object($result)) {
- $rows[] = array($feed->title, $feed->attributes, format_plural($feed->items, "item", "items"), ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never"), ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never"), l(t("edit feed"), "admin/import/edit/feed/$feed->fid"), l(t("remove items"), "admin/import/remove/$feed->fid"), l(t("update items"), "admin/import/update/$feed->fid"));
+ $rows[] = array($feed->title, $feed->attributes, format_plural($feed->items, "1 item", "%count items"), ($feed->timestamp ? format_interval(time() - $feed->timestamp) ." ago" : "never"), ($feed->timestamp ? format_interval($feed->timestamp + $feed->refresh - time()) ." left" : "never"), l(t("edit feed"), "admin/import/edit/feed/$feed->fid"), l(t("remove items"), "admin/import/remove/$feed->fid"), l(t("update items"), "admin/import/update/$feed->fid"));
}
$output .= table($header, $rows);
diff --git a/modules/poll.module b/modules/poll.module
index 90b23cda35ac..b4298f0993cf 100644
--- a/modules/poll.module
+++ b/modules/poll.module
@@ -221,7 +221,7 @@ function poll_page() {
$result = db_query("SELECT n.nid, n.title, p.active, SUM(c.chvotes) AS votes FROM node n LEFT JOIN poll p ON n.nid=p.nid LEFT JOIN poll_choices c ON n.nid=c.nid WHERE type = 'poll' AND status = '1' AND moderate = '0' GROUP BY n.nid, n.title, p.active, n.created ORDER BY n.created DESC");
$output = "
$value | $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "vote", "votes") .")" : "") ." |
$value | $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "1 vote", "%count votes") .")" : "") ." |
$value | $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "vote", "votes") .")" : "") ." |
$value | $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "1 vote", "%count votes") .")" : "") ." |