feat: get rid of disk access

v1.18.x
Barış Soner Uşaklı 6 years ago
parent eeab7d2004
commit ed5d2d6d15

@ -7,6 +7,14 @@ var async = require('async');
var Languages = module.exports;
var languagesPath = path.join(__dirname, '../build/public/language');
Languages.timeagoCodes = [
'af', 'ar', 'az-short', 'az', 'bg', 'bs', 'ca', 'cs', 'cy', 'da', 'de-short', 'de', 'dv',
'el', 'en-short', 'en', 'es-short', 'es', 'et', 'eu', 'fa-short', 'fa', 'fi', 'fr-short', 'fr',
'gl', 'he', 'hr', 'hu', 'hy', 'id', 'is', 'it-short', 'it', 'ja', 'jv', 'ko', 'ky', 'lt', 'lv',
'mk', 'nl', 'no', 'pl', 'pt-br-short', 'pt-br', 'pt-short', 'pt', 'ro', 'rs', 'ru', 'rw', 'si',
'sk', 'sl', 'sr', 'sv', 'th', 'tr-short', 'tr', 'uk', 'uz', 'vi', 'zh-CN', 'zh-TW',
];
Languages.get = function (language, namespace, callback) {
fs.readFile(path.join(languagesPath, language, namespace + '.json'), { encoding: 'utf-8' }, function (err, data) {
if (err) {

@ -1,6 +1,5 @@
'use strict';
var path = require('path');
var async = require('async');
var nconf = require('nconf');
var jsesc = require('jsesc');
@ -17,7 +16,6 @@ var translator = require('../translator');
var privileges = require('../privileges');
var languages = require('../languages');
var utils = require('../utils');
var file = require('../file');
var controllers = {
api: require('../controllers/api'),
@ -239,20 +237,18 @@ module.exports = function (middleware) {
async.parallel({
scripts: async.apply(plugins.fireHook, 'filter:scripts.get', []),
timeagoLocale: (next) => {
const userLang = res.locals.config.userLang;
const pathToLocaleFile = '/vendor/jquery/timeago/locales/jquery.timeago.' + utils.userLangToTimeagoCode(userLang) + '.js';
async.waterfall([
async.apply(languages.list),
(languages, next) => {
if (!languages.some(obj => obj.code === userLang)) {
return next(null, false);
}
async.apply(languages.listCodes),
(languageCodes, next) => {
const userLang = res.locals.config.userLang;
const timeagoCode = utils.userLangToTimeagoCode(userLang);
file.exists(path.join(__dirname, '../../public', pathToLocaleFile), next);
},
(exists, next) => {
next(null, exists ? (nconf.get('relative_path') + '/assets' + pathToLocaleFile) : null);
if (languageCodes.includes(userLang) && languages.timeagoCodes.includes(timeagoCode)) {
const pathToLocaleFile = '/vendor/jquery/timeago/locales/jquery.timeago.' + timeagoCode + '.js';
next(null, (nconf.get('relative_path') + '/assets' + pathToLocaleFile));
} else {
next(null, false);
}
},
], next);
},

Loading…
Cancel
Save