refs #5878 perf: handle when locale not founded
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-01-03 07:38:18 +01:00
parent 3a6e17cd5f
commit 40a269c358
2 changed files with 8 additions and 7 deletions

View File

@ -32,8 +32,7 @@ module.exports = function() {
if (err.statusCode == 422) {
try {
let code;
let messages = err.details.messages;
for (code in messages) break;
let {messages} = err.details;
err.message = req.__(messages[code][0]);
return next(err);
} catch (e) {}
@ -44,7 +43,6 @@ module.exports = function() {
return next(new UserError(req.__(err.sqlMessage)));
// Logs error to console
let env = process.env.NODE_ENV;
let useCustomLogging = env && env != 'development' &&
(!err.statusCode || err.statusCode >= 500);

View File

@ -1,11 +1,13 @@
const SLASH = '/';
const MODULES = 'modules';
const BACK = 'back';
const path = require('path');
const glob = require('glob');
const modulesPath = `modules/**/back/locale/**/**.yml`;
const modulesPath = `${MODULES}/**/${BACK}/locale/**/**.yml`;
const pathResolve = path.resolve(modulesPath);
const modelsLocale = glob.sync(pathResolve, {}).map((f, data) => {
const modelsLocale = glob.sync(pathResolve, {}).map(f => {
const file = require(f);
const model = f.substring(f.indexOf('modules'), f.indexOf('back') - 1).split(SLASH)[1];
const model = f.substring(f.indexOf(MODULES), f.indexOf(BACK) - 1).split(SLASH)[1];
const locale = path.parse(f).base.split('.')[0];
return [keyMap(model, locale), file.columns];
}
@ -96,7 +98,8 @@ module.exports = {
}
}
if (tag) {
const tagValue = mapLocale.get(keyMap(moduleOriginal, $t.getLocale()))[tag];
let tagValue = mapLocale.get(keyMap(moduleOriginal, $t.getLocale()))[tag];
if (!tagValue) tagValue = tag;
return {tag, tagValue};
}
} catch (error) {