mirror of
https://github.com/strapi/strapi.git
synced 2025-07-22 16:37:13 +00:00
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const { getService } = require('../../utils');
|
|
|
|
module.exports = async () => {
|
|
const { sendDidInitializeEvent } = getService('metrics');
|
|
const { decorator } = getService('entity-service-decorator');
|
|
const { initDefaultLocale } = getService('locales');
|
|
const { sectionsBuilder, actions, conditions, engine } = getService('permissions');
|
|
|
|
// Entity Service
|
|
strapi.entityService.decorate(decorator);
|
|
|
|
// Data
|
|
await initDefaultLocale();
|
|
|
|
// Sections Builder
|
|
sectionsBuilder.registerLocalesPropertyHandler();
|
|
|
|
// Actions
|
|
await actions.registerI18nActions();
|
|
actions.registerI18nActionsHooks();
|
|
actions.updateActionsProperties();
|
|
|
|
// Conditions
|
|
await conditions.registerI18nConditions();
|
|
|
|
// Engine/Permissions
|
|
engine.registerI18nPermissionsHandlers();
|
|
|
|
// Hooks & Models
|
|
registerModelsHooks();
|
|
|
|
sendDidInitializeEvent();
|
|
};
|
|
|
|
const registerModelsHooks = () => {
|
|
Object.values(strapi.models)
|
|
.filter(model => getService('content-types').isLocalizedContentType(model))
|
|
.forEach(model => {
|
|
strapi.db.lifecycles.register({
|
|
model: model.uid,
|
|
async beforeCreate(data) {
|
|
await getService('localizations').assignDefaultLocale(data);
|
|
},
|
|
});
|
|
});
|
|
|
|
strapi.db.lifecycles.register({
|
|
model: 'plugins::i18n.locale',
|
|
|
|
async afterCreate() {
|
|
await getService('permissions').actions.syncSuperAdminPermissionsWithLocales();
|
|
},
|
|
|
|
async afterDelete() {
|
|
await getService('permissions').actions.syncSuperAdminPermissionsWithLocales();
|
|
},
|
|
});
|
|
};
|