From 9a23223e253d95377123a9b4b49a54cc8cdbe744 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Tue, 21 Jan 2003 22:44:25 +0000 Subject: [PATCH] - Applied Ori's format_plural() patch; see mailing list for details. NOTE: some modules in the contributions repository might need to be updated. --- includes/common.inc | 18 ++++++++++++++++-- modules/aggregator.module | 2 +- modules/aggregator/aggregator.module | 2 +- modules/cloud.module | 6 +++--- modules/comment.module | 4 ++-- modules/comment/comment.module | 4 ++-- modules/import.module | 2 +- modules/poll.module | 4 ++-- modules/poll/poll.module | 4 ++-- modules/statistics.module | 6 +++--- modules/statistics/statistics.module | 6 +++--- modules/throttle.module | 2 +- modules/throttle/throttle.module | 2 +- modules/tracker.module | 2 +- modules/tracker/tracker.module | 2 +- 15 files changed, 40 insertions(+), 26 deletions(-) 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 .= "<br />". t("Updated < 1 hours ago:"); + $output .= "<br />". t("Updated less than one hour ago:"); } else { - $output .= "<br />". t("Updated %a ago:", array("%a" => format_plural($hour, "hour", "hours"))); + $output .= "<br />". format_plural($hour, "Updated an hour ago:", "Updated %count hours ago:"); } } else if ($list) { - $output .= "<br />". t("Updated more than %a ago:", array("%a" => format_plural($hour, "hour", "hours"))); + $output .= "<br />". 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 = "<ul>"; while ($node = db_fetch_object($result)) { - $output .= "<li>". l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "vote", "votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>"; + $output .= "<li>".l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "1 vote", "%count votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>"; } $output .= "</ul>"; $theme->box(t("Polls"), $output); @@ -328,7 +328,7 @@ function poll_view_results(&$node, $main, $block, $links) { $width = round($node->chvotes[$key] * 100 / $votesmax); $percentage = round($node->chvotes[$key] * 100 / max($votestotal, 1)); - $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" align=\"center\"><tr><td>$value</td><td><div align=\"right\"> $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "vote", "votes") .")" : "") ."</div></td></tr></table>"; + $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" align=\"center\"><tr><td>$value</td><td><div align=\"right\"> $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "1 vote", "%count votes") .")" : "") ."</div></td></tr></table>"; if ($width == 0) { $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" align=\"center\"><tr><td class=\"pollbg\" width=\"100%\"> </td></tr></table>"; } diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 90b23cda35ac..b4298f0993cf 100644 --- a/modules/poll/poll.module +++ b/modules/poll/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 = "<ul>"; while ($node = db_fetch_object($result)) { - $output .= "<li>". l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "vote", "votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>"; + $output .= "<li>".l($node->title, "node/view/$node->nid") ." - ". format_plural($node->votes, "1 vote", "%count votes") ." - ". ($node->active ? t("open") : t("closed")) ."</li>"; } $output .= "</ul>"; $theme->box(t("Polls"), $output); @@ -328,7 +328,7 @@ function poll_view_results(&$node, $main, $block, $links) { $width = round($node->chvotes[$key] * 100 / $votesmax); $percentage = round($node->chvotes[$key] * 100 / max($votestotal, 1)); - $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" align=\"center\"><tr><td>$value</td><td><div align=\"right\"> $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "vote", "votes") .")" : "") ."</div></td></tr></table>"; + $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" align=\"center\"><tr><td>$value</td><td><div align=\"right\"> $percentage%". (!$block ? " (". format_plural($node->chvotes[$key], "1 vote", "%count votes") .")" : "") ."</div></td></tr></table>"; if ($width == 0) { $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" align=\"center\"><tr><td class=\"pollbg\" width=\"100%\"> </td></tr></table>"; } diff --git a/modules/statistics.module b/modules/statistics.module index ccb854ffd2b6..ff0c127ccd04 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -90,10 +90,10 @@ function statistics_link($type, $node = 0, $main = 0) { $statistics = statistics_get($node->nid); if ($statistics) { if (user_access("administer statistics")) { - $links[] = l(format_plural($statistics[totalcount], t("read"), t("reads")), "admin/statistics/referrers/$node->nid"); + $links[] = l(format_plural($statistics[totalcount], "1 read", "%count reads"), "admin/statistics/referrers/$node->nid"); } else { - $links[] = format_plural($statistics[totalcount], t("read"), t("reads")); + $links[] = format_plural($statistics[totalcount], "1 read", "%count reads"); } } } @@ -765,7 +765,7 @@ function statistics_display_online_block() { } /* format the output with proper grammar */ - $output .= t("There %verb currently %members and %visitors online.", array("%verb" => ($users == 1 ? "is" : "are"), "%members" => format_plural($users, "user", "users"), "%visitors" => format_plural($guests, "guest", "guests"))); + $output .= t("There %verb currently %members and %visitors online.", array("%verb" => ($users == 1 ? "is" : "are"), "%members" => format_plural($users, "1 user", "%count users"), "%visitors" => format_plural($guests, "1 guest", "%count guests"))); if (user_access("access userlist") && $users) { /* Display a list of currently online users */ diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index ccb854ffd2b6..ff0c127ccd04 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -90,10 +90,10 @@ function statistics_link($type, $node = 0, $main = 0) { $statistics = statistics_get($node->nid); if ($statistics) { if (user_access("administer statistics")) { - $links[] = l(format_plural($statistics[totalcount], t("read"), t("reads")), "admin/statistics/referrers/$node->nid"); + $links[] = l(format_plural($statistics[totalcount], "1 read", "%count reads"), "admin/statistics/referrers/$node->nid"); } else { - $links[] = format_plural($statistics[totalcount], t("read"), t("reads")); + $links[] = format_plural($statistics[totalcount], "1 read", "%count reads"); } } } @@ -765,7 +765,7 @@ function statistics_display_online_block() { } /* format the output with proper grammar */ - $output .= t("There %verb currently %members and %visitors online.", array("%verb" => ($users == 1 ? "is" : "are"), "%members" => format_plural($users, "user", "users"), "%visitors" => format_plural($guests, "guest", "guests"))); + $output .= t("There %verb currently %members and %visitors online.", array("%verb" => ($users == 1 ? "is" : "are"), "%members" => format_plural($users, "1 user", "%count users"), "%visitors" => format_plural($guests, "1 guest", "%count guests"))); if (user_access("access userlist") && $users) { /* Display a list of currently online users */ diff --git a/modules/throttle.module b/modules/throttle.module index 4756fb2bc230..ed95241eb639 100644 --- a/modules/throttle.module +++ b/modules/throttle.module @@ -130,7 +130,7 @@ function throttle_display_throttle_block() { $output .= "Probability: $probability%<br />\n"; if ($recent_activity["hits"]) { $output .= "<br />This site has served "; - $output .= format_plural($recent_activity["hits"] , " page", " pages"); + $output .= format_plural($recent_activity["hits"] , "1 page", "%count pages"); $output .= " in the past minute."; } } diff --git a/modules/throttle/throttle.module b/modules/throttle/throttle.module index 4756fb2bc230..ed95241eb639 100644 --- a/modules/throttle/throttle.module +++ b/modules/throttle/throttle.module @@ -130,7 +130,7 @@ function throttle_display_throttle_block() { $output .= "Probability: $probability%<br />\n"; if ($recent_activity["hits"]) { $output .= "<br />This site has served "; - $output .= format_plural($recent_activity["hits"] , " page", " pages"); + $output .= format_plural($recent_activity["hits"] , "1 page", "%count pages"); $output .= " in the past minute."; } } diff --git a/modules/tracker.module b/modules/tracker.module index 065893063d28..725cf1895547 100644 --- a/modules/tracker.module +++ b/modules/tracker.module @@ -37,7 +37,7 @@ function tracker_comments($id = 0) { } while ($node = db_fetch_object($sresult)) { - $output .= format_plural($node->comments, "comment", "comments") ." ". t("attached to node") ." ". l($node->title, "node/view/$node->nid") .":\n"; + $output .= format_plural($node->comments, "1 comment", "%count comments") ." ". t("attached to node") ." ". l($node->title, "node/view/$node->nid") .":\n"; if ($id) { $cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.timestamp > $period AND c.uid = '%d' AND c.nid = '%d' ORDER BY cid DESC", $id, $node->nid); diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index 065893063d28..725cf1895547 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -37,7 +37,7 @@ function tracker_comments($id = 0) { } while ($node = db_fetch_object($sresult)) { - $output .= format_plural($node->comments, "comment", "comments") ." ". t("attached to node") ." ". l($node->title, "node/view/$node->nid") .":\n"; + $output .= format_plural($node->comments, "1 comment", "%count comments") ." ". t("attached to node") ." ". l($node->title, "node/view/$node->nid") .":\n"; if ($id) { $cresult = db_query("SELECT c.*, u.name FROM comments c LEFT JOIN users u ON c.uid = u.uid WHERE c.timestamp > $period AND c.uid = '%d' AND c.nid = '%d' ORDER BY cid DESC", $id, $node->nid); -- GitLab