strapi-plugin-i18n
Version:
This plugin enables to create, to read and to update content in different languages, both from the Admin Panel and from the API
29 lines (24 loc) • 808 B
JavaScript
;
const { getOr, get, isMatch } = require('lodash/fp');
const _ = require('lodash');
module.exports = strapi => {
return {
beforeInitialize() {
strapi.config.middleware.load.before.unshift('i18n');
},
initialize() {
const routes = get('plugins.content-manager.config.routes', strapi);
const routesToAddPolicyTo = routes.filter(
route =>
isMatch({ method: 'POST', path: '/collection-types/:model' }, route) ||
isMatch({ method: 'PUT', path: '/single-types/:model' }, route)
);
routesToAddPolicyTo.forEach(route => {
const policies = getOr([], 'config.policies', route).concat(
'plugins::i18n.validateLocaleCreation'
);
_.set(route, 'config.policies', policies);
});
},
};
};