salix/loopback/util/map-locales.js

24 lines
727 B
JavaScript
Raw Normal View History

const SLASH = '/';
const MODULES = 'modules';
const BACK = 'back';
const path = require('path');
const glob = require('glob');
const modulesPath = `${MODULES}/**/${BACK}/locale/**/**.yml`;
const pathResolve = path.resolve(modulesPath);
const modelsLocale = glob.sync(pathResolve, {}).reduce((acc, f) => {
const file = require(f);
const model = f.substring(f.indexOf(MODULES), f.indexOf(BACK) - 1).split(SLASH)[1];
const locale = path.parse(f).base.split('.')[0];
if (!acc[locale]) acc[locale] = {};
acc[locale] = Object.assign(acc[locale], file.columns);
return acc;
}, {}
);
function keyMap(model, local, connector = '_') {
return `${model}${connector}${local}`;
}
module.exports =modelsLocale;