@@ -244,35 +244,41 @@ export default class I18N extends AdminForthPlugin {
244244
245245 // add hook on edit of any translation
246246 resourceConfig . hooks . edit . afterSave . push ( async ( { updates, oldRecord } : { updates : any , oldRecord ?: any } ) : Promise < { ok : boolean , error ?: string } > => {
247- console . log ( '🪲edit.afterSave' , JSON . stringify ( updates , null , 2 ) , '-----' , JSON . stringify ( oldRecord , null , 2 ) ) ;
248247 if ( oldRecord ) {
249248 // find lang which changed
250249 let langsChanged : LanguageCode [ ] = [ ] ;
251250 for ( const lang of this . options . supportedLanguages ) {
252251 if ( lang === 'en' ) {
253252 continue ;
254253 }
254+ if ( updates [ this . trFieldNames [ lang ] ] ) {
255+ langsChanged . push ( lang ) ;
256+ }
255257 }
256-
258+
257259 // clear frontend cache for all langsChanged
258260 for ( const lang of langsChanged ) {
259- this . cache . clear ( `${ this . resourceConfig . resourceId } :frontend:${ lang } ` ) ;
261+ if ( oldRecord [ this . options . categoryFieldName ] === 'frontend' ) {
262+ this . cache . clear ( `${ this . resourceConfig . resourceId } :frontend:${ lang } ` ) ;
263+ } else {
264+ this . cache . clear ( `${ this . resourceConfig . resourceId } :${ oldRecord [ this . options . categoryFieldName ] } :${ lang } :${ oldRecord [ this . enFieldName ] } ` ) ;
265+ }
260266 }
261-
262267 this . updateUntranslatedMenuBadge ( ) ;
263-
264268 }
265269 // clear frontend cache for all lan
266-
267-
268270 return { ok : true } ;
269271 } ) ;
270272
271273 // add hook on delete of any translation to reset cache
272274 resourceConfig . hooks . delete . afterSave . push ( async ( { record } : { record : any } ) : Promise < { ok : boolean , error ?: string } > => {
273275 for ( const lang of this . options . supportedLanguages ) {
274- this . cache . clear ( `${ this . resourceConfig . resourceId } :frontend:${ lang } ` ) ;
275- this . cache . clear ( `${ this . resourceConfig . resourceId } :${ record [ this . options . categoryFieldName ] } :${ lang } :${ record [ this . enFieldName ] } ` ) ;
276+ // if frontend, clear frontend cache
277+ if ( record [ this . options . categoryFieldName ] === 'frontend' ) {
278+ this . cache . clear ( `${ this . resourceConfig . resourceId } :frontend:${ lang } ` ) ;
279+ } else {
280+ this . cache . clear ( `${ this . resourceConfig . resourceId } :${ record [ this . options . categoryFieldName ] } :${ lang } :${ record [ this . enFieldName ] } ` ) ;
281+ }
276282 }
277283 this . updateUntranslatedMenuBadge ( ) ;
278284 return { ok : true } ;
@@ -349,7 +355,7 @@ export default class I18N extends AdminForthPlugin {
349355 // if optional `confirm` is provided, user will be asked to confirm action
350356 confirm : 'Are you sure you want to translate selected items?' ,
351357 state : 'selected' ,
352- allowed : ( { resource, adminUser, selectedIds, allowedActions } ) => {
358+ allowed : async ( { resource, adminUser, selectedIds, allowedActions } ) => {
353359 console . log ( 'allowedActions' , JSON . stringify ( allowedActions ) ) ;
354360 return allowedActions . edit ;
355361 } ,
@@ -569,7 +575,7 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
569575 Object . entries ( updateStrings ) . map (
570576 async ( [ _ , { updates, strId } ] : [ string , { updates : any , category : string , strId : string } ] ) => {
571577 // because this will translate all languages, we can set completedLangs to all languages
572- const futureCompletedFieldValue = this . computeCompletedFieldValue ( updates ) ;
578+ const futureCompletedFieldValue = await this . computeCompletedFieldValue ( updates ) ;
573579
574580 await this . adminforth . resource ( this . resourceConfig . resourceId ) . update ( strId , {
575581 ...updates ,
0 commit comments