Skip to content

Commit 2a2b20b

Browse files
committed
fix: use useI18n instead of window.i18n
1 parent 6bf1a19 commit 2a2b20b

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

adminforth/spa/src/main.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ import { createPinia } from 'pinia'
55

66
import App from './App.vue'
77
import router from './router'
8-
import { initI18n } from './i18n'
98

109
export const app: ReturnType<typeof createApp> = createApp(App)
1110
/* IMPORTANT:ADMINFORTH COMPONENT REGISTRATIONS */
1211

1312
app.use(createPinia())
1413
app.use(router)
1514

16-
// get access to i18n instance outside components
17-
window.i18n = initI18n(app);
18-
1915

2016
/* IMPORTANT:ADMINFORTH CUSTOM USES */
2117

adminforth/spa/src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import adminforth from './adminforth';
99
import sanitizeHtml from 'sanitize-html'
1010
import debounce from 'debounce';
1111
import type { AdminForthResourceColumnInputCommon, Predicate } from '@/types/Common';
12+
import { useI18n } from 'vue-i18n';
1213

1314
const LS_LANG_KEY = `afLanguage`;
1415
const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
1516
const ITEMS_PER_PAGE_LIMIT = 100;
17+
const { t } = useI18n();
1618

1719
export async function callApi({path, method, body, headers}: {
1820
path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
@@ -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

Comments
 (0)