From 3887fc678b9ab8cc74b376ea17db07b37a216f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 8 Sep 2019 21:44:22 -0400 Subject: [PATCH] fix: #7824, update timeago settings on userlanguage change --- public/src/client/account/settings.js | 11 +++++++---- public/src/overrides.js | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js index 37d6f93f19..a6fb10073c 100644 --- a/public/src/client/account/settings.js +++ b/public/src/client/account/settings.js @@ -81,11 +81,11 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds' } app.alertSuccess('[[success:settings-saved]]'); - var requireReload = false; + var languageChanged = false; for (var key in newSettings) { if (newSettings.hasOwnProperty(key)) { if (key === 'userLang' && config.userLang !== newSettings.userLang) { - requireReload = true; + languageChanged = true; } if (config.hasOwnProperty(key)) { config[key] = newSettings[key]; @@ -95,13 +95,16 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds' sounds.loadMap(); - if (requireReload && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) { + if (languageChanged && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) { translator.translate('[[language:dir]]', config.userLang, function (translated) { var htmlEl = $('html'); htmlEl.attr('data-dir', translated); htmlEl.css('direction', translated); }); - ajaxify.refresh(); + $.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + utils.userLangToTimeagoCode(config.userLang) + '.js', function () { + overrides.overrideTimeago(); + ajaxify.refresh(); + }); } }); } diff --git a/public/src/overrides.js b/public/src/overrides.js index 84f6bbb393..a0ae5af1ad 100644 --- a/public/src/overrides.js +++ b/public/src/overrides.js @@ -108,9 +108,12 @@ if (typeof window !== 'undefined') { } }); }()); - + var timeagoFn; overrides.overrideTimeago = function () { - var timeagoFn = $.fn.timeago; + if (!timeagoFn) { + timeagoFn = $.fn.timeago; + } + if (parseInt(config.timeagoCutoff, 10) === 0) { $.timeago.settings.cutoff = 1; } else if (parseInt(config.timeagoCutoff, 10) > 0) {