From c12b42180d084ebcf2105130b2d14872cda42a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 20 Dec 2017 22:08:44 -0500 Subject: [PATCH] closes #6189 --- public/src/modules/notifications.js | 16 ++++++------- public/src/modules/translator.js | 36 +++++++++++++++++------------ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index a215c19475..8ce876eebe 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -137,14 +137,14 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator', 'ben return parseInt(a.datetime, 10) > parseInt(b.datetime, 10) ? -1 : 1; }); - translator.toggleTimeagoShorthand(); - for (var i = 0; i < notifs.length; i += 1) { - notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10))); - } - translator.toggleTimeagoShorthand(); - - Benchpress.parse('partials/notifications_list', { notifications: notifs }, function (html) { - notifList.translateHtml(html); + translator.toggleTimeagoShorthand(function () { + for (var i = 0; i < notifs.length; i += 1) { + notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10))); + } + translator.toggleTimeagoShorthand(); + Benchpress.parse('partials/notifications_list', { notifications: notifs }, function (html) { + notifList.translateHtml(html); + }); }); }); }; diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index 817f6095b6..6376d9e4d0 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -576,23 +576,29 @@ adaptor.getTranslations(language, namespace, callback); }, - toggleTimeagoShorthand: function toggleTimeagoShorthand() { - var tmp = assign({}, jQuery.timeago.settings.strings); - jQuery.timeago.settings.strings = assign({}, adaptor.timeagoShort); - adaptor.timeagoShort = assign({}, tmp); + toggleTimeagoShorthand: function toggleTimeagoShorthand(callback) { + function toggle() { + var tmp = assign({}, jQuery.timeago.settings.strings); + jQuery.timeago.settings.strings = assign({}, adaptor.timeagoShort); + adaptor.timeagoShort = assign({}, tmp); + if (typeof callback === 'function') { + callback(); + } + } + + if (!adaptor.timeagoShort) { + var languageCode = utils.userLangToTimeagoCode(config.userLang); + var originalSettings = assign({}, jQuery.timeago.settings.strings); + jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () { + adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings); + jQuery.timeago.settings.strings = assign({}, originalSettings); + toggle(); + }); + } else { + toggle(); + } }, prepareDOM: function prepareDOM() { - // Load the appropriate timeago locale file, - // and correct NodeBB language codes to timeago codes, if necessary - var languageCode = utils.userLangToTimeagoCode(config.userLang); - - adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings); - - jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () { - // Switch back to long-form - adaptor.toggleTimeagoShorthand(); - }); - // Add directional code if necessary adaptor.translate('[[language:dir]]', function (value) { if (value && !$('html').attr('data-dir')) {