2021-01-22 17:57:15 +01:00
|
|
|
'use strict';
|
|
|
|
|
2021-02-15 11:24:28 +01:00
|
|
|
const { capitalize } = require('lodash/fp');
|
|
|
|
const { getService } = require('../../utils');
|
2021-01-25 20:58:33 +01:00
|
|
|
|
|
|
|
const actions = ['create', 'read', 'update', 'delete'].map(uid => ({
|
|
|
|
section: 'settings',
|
|
|
|
category: 'Internationalization',
|
|
|
|
subCategory: 'Locales',
|
|
|
|
pluginName: 'i18n',
|
|
|
|
displayName: capitalize(uid),
|
|
|
|
uid: `locale.${uid}`,
|
|
|
|
}));
|
|
|
|
|
2021-02-16 14:36:11 +01:00
|
|
|
module.exports = async () => {
|
2021-01-25 20:58:33 +01:00
|
|
|
const { actionProvider } = strapi.admin.services.permission;
|
|
|
|
actionProvider.register(actions);
|
2021-01-04 22:01:37 +01:00
|
|
|
|
2021-03-08 16:39:39 +01:00
|
|
|
getService('entity-service-decorator').decorate();
|
|
|
|
|
2021-03-02 18:32:07 +01:00
|
|
|
await getService('locales').initDefaultLocale();
|
2021-02-16 14:36:11 +01:00
|
|
|
|
2021-02-16 12:08:35 +01:00
|
|
|
Object.values(strapi.models)
|
|
|
|
.filter(model => getService('content-types').isLocalized(model))
|
|
|
|
.forEach(model => {
|
|
|
|
strapi.db.lifecycles.register({
|
|
|
|
model: model.uid,
|
|
|
|
async beforeCreate(data) {
|
2021-02-17 16:59:46 +01:00
|
|
|
await getService('localizations').assignDefaultLocale(data);
|
2021-02-16 12:08:35 +01:00
|
|
|
},
|
2021-02-12 12:23:51 +01:00
|
|
|
});
|
2021-02-16 12:08:35 +01:00
|
|
|
});
|
2021-02-12 12:23:51 +01:00
|
|
|
};
|