@@ -206,7 +206,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
206206 noAuth : true ,
207207 method : 'GET' ,
208208 path : '/get_public_config' ,
209- handler : async ( { body } ) => {
209+ handler : async ( { tr } ) => {
210210
211211 // TODO we need to remove this method and make get_config to return public and private parts for logged in user and only public for not logged in
212212
@@ -225,7 +225,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
225225 loginBackgroundPosition : this . adminforth . config . auth . loginBackgroundPosition ,
226226 title : this . adminforth . config . customization ?. title ,
227227 demoCredentials : this . adminforth . config . auth . demoCredentials ,
228- loginPromptHTML : this . adminforth . config . auth . loginPromptHTML ,
228+ loginPromptHTML : await tr ( this . adminforth . config . auth . loginPromptHTML , 'system.loginPromptHTML' ) ,
229229 loginPageInjections : this . adminforth . config . customization . loginPageInjections ,
230230 rememberMeDays : this . adminforth . config . auth . rememberMeDays ,
231231 } ;
@@ -236,7 +236,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
236236 server . endpoint ( {
237237 method : 'GET' ,
238238 path : '/get_base_config' ,
239- handler : async ( { input, adminUser, cookies} ) : Promise < GetBaseConfigResponse > => {
239+ handler : async ( { input, adminUser, cookies, tr } ) : Promise < GetBaseConfigResponse > => {
240240 let username = ''
241241 let userFullName = ''
242242
@@ -323,6 +323,25 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
323323 userFullnameField : this . adminforth . config . auth . userFullNameField ,
324324 }
325325
326+ // translate menu labels
327+ const translateRoutines : Promise < void > [ ] = [ ] ;
328+ newMenu . forEach ( ( menuItem ) => {
329+ translateRoutines . push ( ( async ( ) => {
330+ if ( menuItem . label ) {
331+ menuItem . label = await tr ( menuItem . label , `menu.${ menuItem . _itemId } ` ) ;
332+ }
333+ } ) ( ) )
334+ if ( menuItem . children ) {
335+ menuItem . children . forEach ( ( child ) => {
336+ translateRoutines . push ( ( async ( ) => {
337+ if ( child . label ) {
338+ child . label = await tr ( child . label , `menu.${ child . _itemId } ` ) ;
339+ }
340+ } ) ( ) )
341+ } )
342+ }
343+ } ) ;
344+ await Promise . all ( translateRoutines ) ;
326345
327346 // strip all backendOnly fields or not described in adminForth fields from dbUser
328347 // (when user defines column and does not set backendOnly, we assume it is not backendOnly)
@@ -423,19 +442,51 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
423442 } )
424443 ) ;
425444
445+ // translate
446+ const translateRoutines : Record < string , Promise < string > > = { } ;
447+ translateRoutines . resLabel = tr ( resource . label , `resource.${ resource . resourceId } ` ) ;
448+ resource . columns . forEach ( ( col , i ) => {
449+ translateRoutines [ `resCol${ i } ` ] = tr ( col . label , `resource.${ resource . resourceId } ` ) ;
450+ } )
451+ allowedBulkActions . forEach ( ( action , i ) => {
452+ if ( action . label ) {
453+ translateRoutines [ `bulkAction${ i } ` ] = tr ( action . label , `resource.${ resource . resourceId } ` ) ;
454+ }
455+ if ( action . confirm ) {
456+ translateRoutines [ `bulkActionConfirm${ i } ` ] = tr ( action . confirm , `resource.${ resource . resourceId } ` ) ;
457+ }
458+ } ) ;
459+
460+ const translated : Record < string , string > = { } ;
461+ await Promise . all (
462+ Object . entries ( translateRoutines ) . map ( async ( [ key , value ] ) => {
463+ translated [ key ] = await value ;
464+ } )
465+ ) ;
466+
467+ console . log ( '🗣️translated' , translated ) ;
468+
469+
426470 const toReturn = {
427471 ...resource ,
428- columns : await Promise . all (
429- resource . columns . map ( async ( col ) => {
472+ label : translated . resLabel ,
473+ columns : resource . columns . map (
474+ ( col , i ) => {
430475 return {
431476 ...col ,
432- label : await tr ( col . label , `resource. ${ resource . resourceId } ` ) ,
477+ label : translated [ `resCol ${ i } ` ] ,
433478 }
434- } )
479+ }
435480 ) ,
436481 options : {
437482 ...resource . options ,
438- bulkActions : allowedBulkActions ,
483+ bulkActions : allowedBulkActions . map (
484+ ( action , i ) => ( {
485+ ...action ,
486+ label : action . label ? translated [ `bulkAction${ i } ` ] : action . label ,
487+ confirm : action . confirm ? translated [ `bulkActionConfirm${ i } ` ] : action . confirm ,
488+ } )
489+ ) ,
439490 allowedActions,
440491 }
441492 }
@@ -865,11 +916,11 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
865916 server . endpoint ( {
866917 method : 'POST' ,
867918 path : '/start_bulk_action' ,
868- handler : async ( { body, adminUser } ) => {
919+ handler : async ( { body, adminUser, tr } ) => {
869920 const { resourceId, actionId, recordIds } = body ;
870921 const resource = this . adminforth . config . resources . find ( ( res ) => res . resourceId == resourceId ) ;
871922 if ( ! resource ) {
872- return { error : `Resource ' $ {resourceId } ' not found` } ;
923+ return { error : await tr ( `Resource {resourceId} not found` , 'errors' , { resourceId } ) } ;
873924 }
874925 const { allowedActions } = await interpretResource (
875926 adminUser ,
@@ -881,16 +932,16 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
881932
882933 const action = resource . options . bulkActions . find ( ( act ) => act . id == actionId ) ;
883934 if ( ! action ) {
884- return { error : `Action ' $ {actionId } ' not found` } ;
935+ return { error : await tr ( `Action {actionId} not found` , 'errors' , { actionId } ) } ;
885936 }
886937
887938 if ( action . allowed ) {
888939 const execAllowed = await action . allowed ( { adminUser, resource, selectedIds : recordIds , allowedActions } ) ;
889940 if ( ! execAllowed ) {
890- return { error : `Action ' $ {actionId } ' is not allowed` } ;
941+ return { error : await tr ( `Action {actionId} not allowed` , 'errors' , { actionId } ) } ;
891942 }
892943 }
893- const response = await action . action ( { selectedIds : recordIds , adminUser, resource} ) ;
944+ const response = await action . action ( { selectedIds : recordIds , adminUser, resource, tr } ) ;
894945
895946 return {
896947 actionId,
0 commit comments