diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js
index 46e6833806..319d88041f 100644
--- a/public/src/modules/notifications.js
+++ b/public/src/modules/notifications.js
@@ -25,11 +25,14 @@ define('notifications', ['sounds'], function(sound) {
image = '';
}
- return '
' + image + '' + utils.relativeTime(notification.datetime, true) + '' + notification.bodyShort + '';
+ return '' + image + '' + $.timeago(new Date(parseInt(notification.datetime, 10))) + '' + notification.bodyShort + '';
}
var x, html = '';
+ // Switch to shorthand
+ translator.toggleTimeagoShorthand();
+
if (!err && (data.read.length + data.unread.length) > 0) {
var image = '';
for (x = 0; x < data.unread.length; x++) {
@@ -43,6 +46,9 @@ define('notifications', ['sounds'], function(sound) {
html += '[[notifications:no_notifs]]';
}
+ // Switch back to original timeago strings
+ translator.toggleTimeagoShorthand();
+
html += '[[notifications:see_all]]';
notifList.translateHtml(html);
diff --git a/public/src/translator.js b/public/src/translator.js
index 07794f360c..5b052af216 100644
--- a/public/src/translator.js
+++ b/public/src/translator.js
@@ -85,6 +85,34 @@
}
};
+ translator.toggleTimeagoShorthand = function() {
+ if (!translator.timeagoStrings) {
+ translator.timeagoStrings = $.extend({}, jQuery.timeago.settings.strings);
+ jQuery.timeago.settings.strings = {
+ prefixAgo: null,
+ prefixFromNow: null,
+ suffixAgo: "",
+ suffixFromNow: "",
+ seconds: "1m",
+ minute: "1m",
+ minutes: "%dm",
+ hour: "1h",
+ hours: "%dh",
+ day: "1d",
+ days: "%dd",
+ month: "1mo",
+ months: "%dmo",
+ year: "1yr",
+ years: "%dyr",
+ wordSeparator: " ",
+ numbers: []
+ };
+ } else {
+ jQuery.timeago.settings.strings = $.extend({}, translator.timeagoStrings);
+ delete translator.timeagoStrings;
+ }
+ };
+
translator.translate = function (text, language, callback) {
if (typeof language === 'function') {
callback = language;
diff --git a/public/src/utils.js b/public/src/utils.js
index bdb8bf1a81..b9658593cc 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -63,44 +63,6 @@
});
},
- relativeTime: function(timestamp, min) {
- var now = +new Date(),
- difference = now - Math.floor(parseFloat(timestamp));
-
- if(difference < 0) {
- difference = 0;
- }
-
- difference = Math.floor(difference / 1000);
-
- if (difference < 60) {
- return difference + (min ? 's' : ' second') + (difference !== 1 && !min ? 's' : '');
- }
-
- difference = Math.floor(difference / 60);
- if (difference < 60) {
- return difference + (min ? 'm' : ' minute') + (difference !== 1 && !min ? 's' : '');
- }
-
- difference = Math.floor(difference / 60);
- if (difference < 24) {
- return difference + (min ? 'h' : ' hour') + (difference !== 1 && !min ? 's' : '');
- }
-
- difference = Math.floor(difference / 24);
- if (difference < 30) {
- return difference + (min ? 'd' : ' day') + (difference !== 1 && !min ? 's' : '');
- }
-
- difference = Math.floor(difference / 30);
- if (difference < 12) {
- return difference + (min ? 'mon' : ' month') + (difference !== 1 && !min ? 's' : '');
- }
-
- difference = Math.floor(difference / 12);
- return difference + (min ? 'y' : ' year') + (difference !== 1 && !min ? 's' : '');
- },
-
invalidUnicodeChars: XRegExp('[^\\p{L}\\s\\d\\-_]', 'g'),
invalidLatinChars: /[^\w\s\d\-_]/g,
trimRegex: /^\s+|\s+$/g,