diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index b208a0af48..587f22d96b 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -109,17 +109,6 @@ $.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').success(function() { // Switch back to long-form translator.toggleTimeagoShorthand(); - }).fail(function() { - $.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.en-short.js').success(function() { - // Switch back to long-form - translator.toggleTimeagoShorthand(); - }); - }); - }).fail(function() { - $.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.en-short.js').success(function() { - // Switch back to long-form - translator.toggleTimeagoShorthand(); - $.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.en.js'); }); }); diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index bc07719ade..7d324e136e 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -5,6 +5,7 @@ var app, admin: {} }, async = require('async'), + fs = require('fs'), path = require('path'), csrf = require('csurf'), _ = require('underscore'), @@ -302,6 +303,28 @@ middleware.applyBlacklist = function(req, res, next) { }); }; +middleware.processLanguages = function(req, res, next) { + var fallback = req.path.indexOf('-short') === -1 ? 'jquery.timeago.en.js' : 'jquery.timeago.en-short.js', + localPath = path.join(__dirname, '../../public/vendor/jquery/timeago/locales', req.path), + exists; + + try { + exists = fs.accessSync(localPath, fs.F_OK | fs.R_OK); + } catch(e) { + exists = false; + } + + if (exists) { + res.status(200).sendFile(localPath, { + maxAge: app.enabled('cache') ? 5184000000 : 0 + }); + } else { + res.status(200).sendFile(path.join(__dirname, '../../public/vendor/jquery/timeago/locales', fallback), { + maxAge: app.enabled('cache') ? 5184000000 : 0 + }); + } +}; + module.exports = function(webserver) { app = webserver; middleware.admin = require('./admin')(webserver); diff --git a/src/routes/index.js b/src/routes/index.js index 5aaf32b318..c5d2d25178 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -144,11 +144,10 @@ module.exports = function(app, middleware, hotswapIds) { } app.use(middleware.privateUploads); - app.use(relativePath, express.static(path.join(__dirname, '../../', 'public'), { maxAge: app.enabled('cache') ? 5184000000 : 0 })); - + app.use('/vendor/jquery/timeago/locales', middleware.processLanguages); app.use(controllers.handle404); app.use(controllers.handleErrors);