From 527adcba170260436cbee529470a429ea546392d Mon Sep 17 00:00:00 2001 From: selsta Date: Sat, 16 May 2020 17:56:36 +0200 Subject: [PATCH] Utils: simplify for translations --- js/Utils.js | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/js/Utils.js b/js/Utils.js index 51395dce..17ba38b1 100644 --- a/js/Utils.js +++ b/js/Utils.js @@ -55,36 +55,14 @@ function ago(epoch) { var now = new Date().getTime() / 1000; var delta = now - epoch; - if(delta < 60) { - if (delta <= 1) { - return 1 + " " + qsTr("second ago") - } else { - return Math.floor(delta) + " " + qsTr("seconds ago") - } - } else if (delta >= 60 && delta <= 3600) { - if(delta >= 60 && delta < 120){ - return 1 + " " + qsTr("minute ago") - } else { - return parseInt(Math.floor(delta / 60)) + " " + qsTr("minutes ago") - } - } else if (delta >= 3600 && delta <= 86400) { - if(delta >= 3600 && delta < 7200) { - return 1 + " " + qsTr("hour ago") - } else { - return parseInt(Math.floor(delta / 60 / 60)) + " " + qsTr("hours ago") - } - } else if (delta >= 86400){ - if(delta >= 86400 && delta < 172800) { - return 1 + " " + qsTr("day ago") - } else { - var _delta = parseInt(Math.floor(delta / 24 / 60 / 60)); - if(_delta === 1) { - return 1 + " " + qsTr("day ago") - } else { - return _delta + " " + qsTr("days ago") - } - } - } + if(delta < 60) + return qsTr("%n second(s) ago", "0", Math.floor(delta)) + else if (delta >= 60 && delta <= 3600) + return qsTr("%n minute(s) ago", "0", Math.floor(delta / 60)) + else if (delta >= 3600 && delta <= 86400) + return qsTr("%n hour(s) ago", "0", Math.floor(delta / 60 / 60)) + else if (delta >= 86400) + return qsTr("%n day(s) ago", "0", Math.floor(delta / 24 / 60 / 60)) } function netTypeToString(){