- Applied Ori's format_plural() patch; see mailing list for details.
NOTE: some modules in the contributions repository might need to be updated.4.2.x
parent
ef0acbf2dd
commit
9a23223e25
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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>";
|
||||
}
|
||||
|
|
|
@ -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>";
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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.";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue