From cee47f78b2af6a58d7d70457b22f986942c96540 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 21 Jan 2019 16:34:33 -0500 Subject: [PATCH] fix: #7289 timeago shorthand toggle fails on non-existant language - Exposing timeagoCodes to frontend - Timeago language and shorthand toggling will fall back to 'en' if the requested language does not exist --- public/src/modules/translator.js | 7 +++++++ src/controllers/api.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index 8bce483e44..0495b23306 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -586,6 +586,10 @@ if (!adaptor.timeagoShort) { var languageCode = utils.userLangToTimeagoCode(config.userLang); + if (!config.timeagoCodes.includes(languageCode + '-short')) { + languageCode = 'en'; + } + 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); @@ -602,6 +606,9 @@ delete adaptor.timeagoShort; var languageCode = utils.userLangToTimeagoCode(config.userLang); + if (!config.timeagoCodes.includes(languageCode + '-short')) { + languageCode = 'en'; + } jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js').done(callback); }, diff --git a/src/controllers/api.js b/src/controllers/api.js index 5f37721935..746f67184f 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -12,6 +12,7 @@ var categories = require('../categories'); var privileges = require('../privileges'); var plugins = require('../plugins'); var translator = require('../translator'); +var languages = require('../languages'); var apiController = module.exports; @@ -62,6 +63,7 @@ apiController.loadConfig = function (req, callback) { config.bootswatchSkin = meta.config.bootswatchSkin || ''; config.enablePostHistory = (meta.config.enablePostHistory || 1) === 1; config.notificationAlertTimeout = meta.config.notificationAlertTimeout || 5000; + config.timeagoCodes = languages.timeagoCodes; if (config.useOutgoingLinksPage) { config.outgoingLinksWhitelist = meta.config['outgoingLinks:whitelist'];