From 50e4c54558b4e93091882344876e24ff0575a6e0 Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Thu, 12 Apr 2012 15:28:49 -0400 Subject: Fix pluralisation issue in Recently Played Previously we would say things like "1 seconds" and "1 hours". Using the magic of ngettext and sprintf we can get rid of the static concatenation order and become theoretically more translatable as well as more correct in English. Also changed the logic a bit, since the old looping method was unfriendly to my brain. --- templates/show_recently_played.inc.php | 60 +++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'templates') diff --git a/templates/show_recently_played.inc.php b/templates/show_recently_played.inc.php index 8a4da36c..a1b08604 100644 --- a/templates/show_recently_played.inc.php +++ b/templates/show_recently_played.inc.php @@ -26,8 +26,6 @@ * @link http://www.ampache.org/ */ -/* Define the time places starting at 0 */ -$time_unit = array('',_('seconds ago'),_('minutes ago'),_('hours ago'),_('days ago'),_('weeks ago'),_('months ago'),_('years ago')); $link = Config::get('use_rss') ? ' ' . AmpacheRSS::get_display('recently_played') : ''; show_box_top(_('Recently Played') . $link, 'box box_recently_played'); ?> @@ -51,34 +49,42 @@ show_box_top(_('Recently Played') . $link, 'box box_recently_played'); = 1) { - $final = $amount; - $time_place++; - if ($time_place <= 2) { - $amount = floor($amount/60); - } - if ($time_place == '3') { - $amount = floor($amount/24); - } - if ($time_place == '4') { - $amount = floor($amount/7); - } - if ($time_place == '5') { - $amount = floor($amount/4); - } - if ($time_place == '6') { - $amount = floor ($amount/12); - } - if ($time_place > '6') { - $final = $amount . '+'; - break; - } + if ($interval < 60) { + $unit = 'seconds'; + } + else if ($interval < 3600) { + $interval = floor($interval / 60); + $unit = 'minutes'; + } + else if ($interval < 86400) { + $interval = floor($interval / 60); + $unit = 'hours'; + } + else if ($interval < 604800) { + $interval = floor($interval / 86400); + $unit = 'days'; + } + else if ($interval < 2592000) { + $interval = floor($interval / 604800); + $unit = 'weeks'; + } + else if ($interval < 31556926) { + $interval = floor($interval / 2592000); + $unit = 'months'; + } + else if ($interval < 631138519) { + $interval = floor($interval / 31556926); + $unit = 'years'; + } + else { + $interval = floor($interval / 315569260); + $unit = 'decades'; } - $time_string = $final . ' ' . $time_unit[$time_place]; + // I wonder how smart gettext is? + $time_string = sprintf(ngettext('%d ' . rtrim($unit, 's') . ' ago', '%d ' . $unit . ' ago', $interval), $interval); $song->format(); ?> -- cgit