File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,12 +15,6 @@ const bootstrap = async (context: { strapi: Core.Strapi }) => {
1515
1616 await strapi . service ( 'plugin::navigation.migrate' ) . migrateRelatedIdToDocumentId ( ) ;
1717
18- strapi . db . lifecycles . subscribe ( {
19- models : [ 'plugin::i18n.locale' ] ,
20- async afterCreate ( event ) {
21- const adminService = getPluginService ( context , 'admin' ) ;
22- await adminService . refreshNavigationLocale ( event . result ?. code ) ;
23- } ,
24- } ) ;
18+
2519} ;
2620export default bootstrap ;
Original file line number Diff line number Diff line change 1- export default { } ;
1+ import { localeMiddleware } from './middleware' ;
2+
3+ export default {
4+ localeMiddleware,
5+ } ;
Original file line number Diff line number Diff line change 1+ import type { Core } from '@strapi/types' ;
2+ import type { Context , Next } from 'koa' ;
3+
4+ export const localeMiddleware = ( { strapi } : { strapi : Core . Strapi } ) => {
5+ const adminService = strapi . plugin ( 'navigation' ) . service ( 'admin' ) ;
6+
7+ return async ( ctx : Context , next : Next ) => {
8+ await next ( ) ;
9+
10+ const isCreateLocaleRoute = ctx . method === 'POST' && ctx . path === '/i18n/locales' ;
11+ if ( ! isCreateLocaleRoute ) return ;
12+
13+ const locale = ( ctx . body as { code ?: string } ) ?. code ;
14+ if ( ! locale || typeof locale !== 'string' ) return ;
15+
16+ try {
17+ await adminService . refreshNavigationLocale ( locale ) ;
18+ } catch ( error ) {
19+ strapi . log . error ( `Failed to refresh navigation for new locale ${ locale } ` , error ) ;
20+ }
21+ } ;
22+ } ;
23+
24+ export default localeMiddleware ;
Original file line number Diff line number Diff line change 11import type { Core } from '@strapi/types' ;
2+ import middlewares from './middlewares' ;
23
34const register = ( { strapi } : { strapi : Core . Strapi } ) => {
4- // register phase
5+ strapi . server . use ( middlewares . localeMiddleware ( { strapi } ) ) ;
56} ;
6-
77export default register ;
You can’t perform that action at this time.
0 commit comments