From 58d39153c616be71a7b7af1bab2038e1471f0f37 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 17 Mar 2011 13:51:55 -0700 Subject: [PATCH] Favored lists in progress: 'foo, bar and baz' --- lib/threadednoticelist.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index 6fb059491a..28e6aa5aa8 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -361,12 +361,12 @@ class ThreadedNoticeListFavesItem extends NoticeListItem $count = count($links); if ($count == 1 && $you) { // darn first person being different from third person! - $msg = _m('FAVELIST', 'You have favored this notice'); + $msg = _m('FAVELIST', 'You have favored this notice.'); } else { - // if 'you' is the first item... - $msg = _m('FAVELIST', '%1$s has favored this notice', '%1$s have favored this notice', $count); + // if 'you' is the first item, + $msg = _m('FAVELIST', '%1$s has favored this notice.', '%1$s have favored this notice.', $count); } - $out = sprintf($msg, implode(', ', $links)); + $out = sprintf($msg, $this->magicList($links)); $this->out->elementStart('li', array('class' => 'notice-faves')); $this->out->raw($out); @@ -376,4 +376,18 @@ class ThreadedNoticeListFavesItem extends NoticeListItem return 0; } } + + function magicList($items) + { + if (count($items) == 0) { + return ''; + } else if (count($items) == 1) { + return $items[0]; + } else { + $first = array_slice($items, 0, -1); + $last = array_slice($items, -1, 1); + // TRANS For building a list such as "You, bob, mary and 5 others have favored this notice". + return sprintf(_m('FAVELIST', '%1$s and %2$s'), implode(', ', $first), implode(', ', $last)); + } + } } -- 2.39.5