load correct timeago settings on cold load instead of after page load
v1.18.x
Baris Usakli 8 years ago
parent 1837ac2015
commit 7538210b07

@ -580,39 +580,13 @@
prepareDOM: function prepareDOM() {
// Load the appropriate timeago locale file,
// and correct NodeBB language codes to timeago codes, if necessary
var languageCode;
switch (config.userLang) {
case 'en-GB':
case 'en-US':
languageCode = 'en';
break;
case 'fa-IR':
languageCode = 'fa';
break;
case 'pt-BR':
languageCode = 'pt-br';
break;
case 'nb':
languageCode = 'no';
break;
default:
languageCode = config.userLang;
break;
}
var languageCode = utils.userLangToTimeagoCode(config.userLang);
jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js').done(function () {
jQuery('.timeago').timeago();
adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings);
adaptor.timeagoShort = assign({}, jQuery.timeago.settings.strings);
// Retrieve the shorthand timeago values as well
jQuery.getScript(config.relative_path + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').done(function () {
// Switch back to long-form
adaptor.toggleTimeagoShorthand();
});
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

@ -103,7 +103,16 @@
hasLanguageKey: function (input) {
return utils.languageKeyRegex.test(input);
},
userLangToTimeagoCode: function (userLang) {
var mapping = {
'en-GB': 'en',
'en-US': 'en',
'fa-IR': 'fa',
'pt-BR': 'pt-br',
nb: 'no',
};
return mapping[userLang] || userLang;
},
// shallow objects merge
merge: function () {
var result = {};

@ -9,6 +9,7 @@ var meta = require('../meta');
var plugins = require('../plugins');
var navigation = require('../navigation');
var translator = require('../translator');
var utils = require('../utils');
var controllers = {
api: require('../controllers/api'),
@ -152,6 +153,8 @@ module.exports = function (middleware) {
return { src: script };
});
addTimeagoLocaleScript(templateValues.scripts, res.locals.config.userLang);
if (req.route && req.route.path === '/') {
modifyTitle(templateValues);
}
@ -168,6 +171,11 @@ module.exports = function (middleware) {
], callback);
};
function addTimeagoLocaleScript(scripts, userLang) {
var languageCode = utils.userLangToTimeagoCode(userLang);
scripts.push({ src: nconf.get('relative_path') + '/assets/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '.js' });
}
middleware.renderFooter = function (req, res, data, callback) {
async.waterfall([
function (next) {

Loading…
Cancel
Save