feat: traducciones en los modelos
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
d6a0580203
commit
843e5ae736
|
@ -2719,3 +2719,7 @@ UPDATE `account`.`user`
|
|||
INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`)
|
||||
VALUES
|
||||
(0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 'open', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all');
|
||||
|
||||
INSERT INTO `vn`.`ticketLog` (`id`, `originFk`, `userFk`, `action`, `changedModel`, `oldInstance`, `newInstance`, `changedModelId`)
|
||||
VALUES
|
||||
(1, 1, 9, 'insert', 'Ticket', '{}', '{"clientFk":1, "nickname": "Bat cave"}', 1);
|
|
@ -33,16 +33,21 @@ export default class Controller extends Section {
|
|||
|
||||
set logs(value) {
|
||||
this._logs = value;
|
||||
if (!value) return;
|
||||
|
||||
if (this.logs) {
|
||||
this.logs.forEach(log => {
|
||||
log.oldProperties = this.getInstance(log.oldInstance);
|
||||
log.newProperties = this.getInstance(log.newInstance);
|
||||
});
|
||||
}
|
||||
const validations = window.validations;
|
||||
value.forEach(log => {
|
||||
let locale = {};
|
||||
try {
|
||||
locale = validations[log.changedModel].locale;
|
||||
} catch (e) {}
|
||||
|
||||
log.oldProperties = this.getInstance(log.oldInstance, locale);
|
||||
log.newProperties = this.getInstance(log.newInstance, locale);
|
||||
});
|
||||
}
|
||||
|
||||
getInstance(instance) {
|
||||
getInstance(instance, locale) {
|
||||
const properties = [];
|
||||
let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/;
|
||||
|
||||
|
@ -51,7 +56,8 @@ export default class Controller extends Section {
|
|||
if (validDate.test(instance[property]))
|
||||
instance[property] = new Date(instance[property]).toLocaleString('es-ES');
|
||||
|
||||
properties.push({key: property, value: instance[property]});
|
||||
const key = locale[property] || property;
|
||||
properties.push({key, value: instance[property]});
|
||||
});
|
||||
return properties;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('modelInfo', {
|
||||
|
@ -19,6 +21,42 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
const modelsLocale = new Map();
|
||||
const modulesDir = path.resolve(`${__dirname}/../../../../modules`);
|
||||
const modules = fs.readdirSync(modulesDir);
|
||||
|
||||
for (const mod of modules) {
|
||||
const modelsDir = path.join(modulesDir, mod, `back/locale`);
|
||||
if (!fs.existsSync(modelsDir)) continue;
|
||||
const models = fs.readdirSync(modelsDir);
|
||||
|
||||
for (const model of models) {
|
||||
const localeDir = path.join(modelsDir, model);
|
||||
const localeFiles = fs.readdirSync(localeDir);
|
||||
|
||||
let modelName = model.charAt(0).toUpperCase() + model.substring(1);
|
||||
modelName = modelName.replace(/-\w/g, match => {
|
||||
return match.charAt(1).toUpperCase();
|
||||
});
|
||||
|
||||
const modelLocale = new Map();
|
||||
modelsLocale.set(modelName, modelLocale);
|
||||
|
||||
for (const localeFile of localeFiles) {
|
||||
const localePath = path.join(localeDir, localeFile);
|
||||
|
||||
const match = localeFile.match(/^([a-z]+)\.yml$/);
|
||||
if (!match) {
|
||||
console.warn(`Skipping wrong model locale file: ${localeFile}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const translations = require(localePath);
|
||||
modelLocale.set(match[1], translations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Self.modelInfo = async function(ctx) {
|
||||
let json = {};
|
||||
let models = Self.app.models;
|
||||
|
@ -49,9 +87,13 @@ module.exports = Self => {
|
|||
jsonValidations[fieldName] = jsonField;
|
||||
}
|
||||
|
||||
const modelLocale = modelsLocale.get(modelName);
|
||||
const locale = modelLocale && modelLocale.get('es');
|
||||
|
||||
json[modelName] = {
|
||||
properties: model.definition.rawProperties,
|
||||
validations: jsonValidations
|
||||
validations: jsonValidations,
|
||||
locale
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
concept: concept
|
||||
quantity: quantity
|
||||
price: price
|
||||
discount: discount
|
||||
reserved: reserved
|
||||
isPicked: is picked
|
||||
created: created
|
|
@ -0,0 +1,7 @@
|
|||
concept: concepto
|
||||
quantity: cantidad
|
||||
price: precio
|
||||
discount: descuento
|
||||
reserved: reservado
|
||||
isPicked: esta seleccionado
|
||||
created: creado
|
Loading…
Reference in New Issue