summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2012-04-12 15:28:49 -0400
committerPaul Arthur <paul.arthur@flowerysong.com>2012-04-12 15:33:36 -0400
commit50e4c54558b4e93091882344876e24ff0575a6e0 (patch)
treea602f065067ac1402b6f7192399cf302c0b6ea47
parent1c2de3015039e229357a8dd724eaddf3d7a56efb (diff)
downloadampache-50e4c54558b4e93091882344876e24ff0575a6e0.tar.gz
ampache-50e4c54558b4e93091882344876e24ff0575a6e0.tar.bz2
ampache-50e4c54558b4e93091882344876e24ff0575a6e0.zip
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.
-rwxr-xr-xdocs/CHANGELOG1
-rw-r--r--templates/show_recently_played.inc.php60
2 files changed, 34 insertions, 27 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index f17de45d..527367a3 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,7 @@
--------------------------------------------------------------------------
v.3.6-Alpha2
+ - Fixed pluralisation issue in Recently Played
- Added support for extracting MBIDs from M4A files
- Fixed parsing of some tag types (most notably M4A)
- Corrected PLS output to work with more players (reported by bhassel)
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');
<?php foreach ($data as $row) {
$row_user = new User($row['user']);
$song = new Song($row['object_id']);
- $amount = intval(time() - $row['date']+2);
- $time_place = '0';
+ $interval = intval(time() - $row['date']);
- while ($amount >= 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();
?>