@@ -9,6 +9,7 @@ import adminforth from './adminforth';
99import sanitizeHtml from 'sanitize-html'
1010import debounce from 'debounce' ;
1111import type { AdminForthResourceColumnInputCommon , Predicate } from '@/types/Common' ;
12+ import { i18nInstance } from './i18n'
1213
1314const LS_LANG_KEY = `afLanguage` ;
1415const MAX_CONSECUTIVE_EMPTY_RESULTS = 2 ;
@@ -19,6 +20,7 @@ export async function callApi({path, method, body, headers}: {
1920 body ?: any
2021 headers ?: Record < string , string >
2122} ) : Promise < any > {
23+ const t = i18nInstance ?. global . t || ( ( s : string ) => s )
2224 const options = {
2325 method,
2426 headers : {
@@ -42,11 +44,11 @@ export async function callApi({path, method, body, headers}: {
4244 // if it is internal error, say to user
4345 if ( e instanceof TypeError && e . message === 'Failed to fetch' ) {
4446 // this is a network error
45- adminforth . alert ( { variant :'danger' , message : window . i18n ?. global ?. t ( 'Network error, please check your Internet connection and try again' ) , } )
47+ adminforth . alert ( { variant :'danger' , message : t ( 'Network error, please check your Internet connection and try again' ) , } )
4648 return null ;
4749 }
4850
49- adminforth . alert ( { variant :'danger' , message : window . i18n ?. global ?. t ( 'Something went wrong, please try again later' ) , } )
51+ adminforth . alert ( { variant :'danger' , message : t ( 'Something went wrong, please try again later' ) , } )
5052 console . error ( `error in callApi ${ path } ` , e ) ;
5153 }
5254}
0 commit comments